[Tex/LaTex] How to edit tables in LyX

lyxtables

I have a problem with re-sizing the table in LyX. When I export it to .pdf its too wide so it goes far out of the border.

Any ideas on how to shrink it, or make it readable in .pdf?

p.s. In LyX, everything seems ok.

Best Answer

You could use any of the methods described in Wider tables in LaTeX, which is the best solution? Here's a LyX take on it:

Insert an ERT before your table and include the necessary LaTeX code, followed by an ERT after to complete the grouping, if necessary. For example:

enter image description here

In the LyX "LaTeX Source" window, this will result in:

\resizebox{\textwidth}{!}{%
\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|c|c|c|c|c|}
\hline 
a & b & c & d & e & f & g & h & i & j & k & l & m & n & o\tabularnewline
\hline 
\hline 
1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15\tabularnewline
\hline 
15 & 14 & 13 & 12 & 11 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1\tabularnewline
\hline 
4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 1 & 2 & 3\tabularnewline
\hline 
\end{tabular}}

which appropriately uses % to avoid a spurious space (as reference, see What is the use of percent signs (%) at the end of lines?). Make sure you add the package graphicx to your LaTeX preamble (Document > Settings... > LaTeX preamble).

Depending on the location of this table, you may have to prepend the ERT with \noindent. For example, inside a table environment, there is usually no indent, while inside the regular document body, indents are common. \noindent would remove this indent.