# How to edit tables in LyX?

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.

-

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:

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.

-
Thanks. I got it now :) – ttwis Jan 20 '13 at 14:57

Many times the problem is not the exposed by Werner of a big table with several columns that must be of reduced (also in font size in this way), but only that there are some long text in some cell that must have some line breaks, but this is not allowed by default in tabular environment.

For example, a table with big font like this:

Produce this awful result in the PDF:

To correct this, al least one column must have a defined width. Select a column in the Lyx screen and go to right-click menu -> More ... -> Configuration -> Column -> Width (or something similar, this is a translation of a LyX in Spanish).

In the above example, setting the width of the three columns to 20% of text width produce this effect in in Lyx screen and PDF view:

Another option for a minor width fix is only reduce the space between cells contents. See Table padding in LyX.

BTW, I know that the table format is ugly. I have not changed the default in LyX to focus on the width problem.

-