10

I have a really long table in LaTeX that spans several pages and is (as it is now) also too wide for the page.

I am using the longtable package with every column width specified with the p{width} command.

The problem is, that most of the rows contain a multicolumn call, and thus are not adhering to the preamble p{width} command, which causes the total width of the table to be too large.

Minimal example:

\begin{longtable}{|p{1in}|p{0.75in}|p{0.5in}|p{0.5in}|>{p{1in}|p{1in}|}
\caption{some cap} \label{somelable}\\
\hline
\multicolumn{2}{|c|}{\textbf{Text Header One}} & \multicolumn{2}{|c|}{\textbf{Text Header Two}} & \multirow{2}{*}{\textbf{Three}} & \multirow{2}{*}{\textbf{Four}} \tabularnewline \cline{1-4}
\textbf{Five} & \textbf{Six} & \textbf{Seven} & \textbf{Eight} &  & \tabularnewline \hline
Some Text String & Longer Text String Here & More Text Here & Text Example & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hlineExample Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & \multicolumn{2}{|l|}{Multi-column Text String that doesn't fit column width} & Text & Text \tabularnewline \hline
Example Text String Two & Longer Text String Example Two & width of box & text & Text & Text  \tabularnewline \hline
\end{longtable} 

I am loading longtable in my preamble, and running pdflatex several times (as outlined in the longtable documentation). It compiles with 0 warnings and 0 errors.

How can I get normal "narrow" cells?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mica
  • 18,501
  • 6
  • 46
  • 43

3 Answers3

8

Have you tried using |p{<sum of widths>}| for the formatting option to \multicolumn?

Just guessing here.

dmckee --- ex-moderator kitten
  • 98,632
  • 24
  • 142
  • 234
  • Worked like a charm. Thanks for the prompt reply! – Mica Jul 10 '09 at 18:56
  • 1
    @IRus The second argument to `\multicolumn` is a format specifier that takes the same meaning as in the second argument to a `tabular` environment. See http://stackoverflow.com/questions/440228/how-can-i-combine-cells-in-a-row-in-a-latex-table for a summary of how to use it. Mica's situation here is an interesting corner case where he was relying on fixed column widths and the multicolumn opening things up too much. – dmckee --- ex-moderator kitten Jun 05 '14 at 01:12
  • Ok, now i understand, how to use this. Thank you! – Ruslan Jun 05 '14 at 17:16
  • 1
    Sum of widths is not enough, especially if you have a lot of columns merged. See https://tex.stackexchange.com/questions/204911/how-to-specify-the-multicolumn-width-in-table-header – Somnium Mar 01 '20 at 10:23
4

You have to give a size parameter to multicolumns even though there is a preamble size. The next example is a multicolumn cell of the size of the table width:

\begin{tabular}{p{0.3\textwidth} p{0.7\textwidth}}
\multicolumn{2}{ p{\textwidth}} {YOUR TEXT HERE}
\end{tabular}
1

\begin{longtable}{p{2.8cm} p{2.8cm} worked for me..