Pedro's blog: db2, mysql, php, linux and performance


Latex longtable issue
10/01/2010, 11:37
Filed under: Latex | Tags: ,

I had a problem with a longtable in LaTeX, the margins where so much big and my table was disappearing on the right side:

Longtable issue

The code was:

\begin{longtable}{| c | c | c |}
\rowcolor[rgb]{0.52, 0.52, 0.52} \textbf{Castellano}  & \textbf{Inglés}  & \textbf{Valenciano}  \\ \hline
Artes decorativas /aplicadas    &    Applied Arts    &    Arts decoratives     \\ \hline

\end{longtable}

For fixing it, I had to write the width of every column, and LaTeX did the rest:

\begin{longtable}{| p{0.30\linewidth} | p{0.30\linewidth}  | p{0.29\linewidth}  |}
\rowcolor[rgb]{0.52, 0.52, 0.52} \textbf{Castellano}  & \textbf{Inglés}  & \textbf{Valenciano}  \\ \hline  \endfirsthead
Artes decorativas /aplicadas    &    Applied Arts    &    Arts decoratives     \\ \hline
\end{longtable}

The result:
Longtable issue
And now everything is working properly, I lost the center property but I don’t care.

If you want, you can use the \endhead, \endfoot and \endlastfoot for adding a line on the table with some text before break the line and at the begging of the new page on the continuation of the table, looks cool:

\begin{longtable}{| p{0.30\linewidth} | p{0.30\linewidth} | p{0.29\linewidth} |}
\rowcolor[rgb]{0.52, 0.52, 0.52} \textbf{Castellano} & \textbf{Inglés} & \textbf{Valenciano} \\ \hline \endfirsthead
\caption[Técnicas]{Técnicas} \label{lsttecnicas} \\ \hline
\rowcolor[rgb]{0.52, 0.52, 0.52} \textbf{Castellano} & \textbf{Inglés} & \textbf{Valenciano} \\ \hline \endfirsthead
\hline Continuación de la tabla \\ \hline \hline \endhead
\hline\hline {\scriptsize Continúa en la página siguiente} \\
\hline \endfoot
\hline\endlastfoot

    Primera línea \\ \hline
    Segunda línea \\ \hline
    ...
\end{longtable}

Cheers!