Here is an MWE:


\begin{longtable}{@{}rrrrrrr@{}} \toprule
    \multicolumn{7}{c}{Vertical} \\
      & \multicolumn{2}{c}{$\langle x^1_{i}, y^1_{i} \rangle$}
      & \multicolumn{2}{c}{$\langle x^2_{i}, y^2_{i} \rangle$}
      & $\measuredangle_{i}$ & $m_{i}$ \endhead \midrule
    &   $\langle 17.90,$ & $27.19 \rangle$
    &   $\langle -192.10,$ & $69.53 \rangle$
    &   $-90.0°$
    &   $29$ \\
    &   $\langle 47.65,$ & $31.32 \rangle$
    &   $\langle -162.35,$ & $73.66 \rangle$
    &   $-90.0°$
    &   $21$ \\
    &   $\langle 85.94,$ & $32.43 \rangle$
    &   $\langle -124.06,$ & $74.77 \rangle$
    &   $-90.0°$
    &   $27$ \\
    &   $\langle 117.53,$ & $34.29 \rangle$
    &   $\langle -92.47,$ & $76.63 \rangle$
    &   $-90.0°$
    &   $23$ \\
    &   $\langle 154.71,$ & $29.83 \rangle$
    &   $\langle -55.29,$ & $72.17 \rangle$
    &   $-90.0°$
    &   $21$ \\
    &   \multicolumn{4}{r}{$\tilde{m} = \frac{1}{n}\sum_{i=1}^{n}m_{i}$} = $24.0$ \\ \bottomrule




Bad width of head of longtable

The obvious problem is that header columns are misaligned. $i$ should be above the numbers (first column) and $m_i$ should be above the last column.

  • 2
    You need to compile two or three times in order that the header and footer of the longtable can be typeset with the correct lengths. As an aside: I'd put the first \midrule before \endhead (with \\ in front of it).
    – egreg
    Sep 29 '12 at 22:10
  • As egerg says you need multiple runs -- this actually needs three runs to stabilize. Sep 29 '12 at 22:10
  • I ran it twice. But now I tried to run it three times and the problem is gone. Sorry, it was a very dumb question. Is it possible that I will ever need to run it four times?
    – nagylzs
    Sep 29 '12 at 22:15
  • 1
    A typographically suggestion: Use {@{}rr@{${},{}$}rr@{${},{}$}rrr@{}} as column specification and remove the commas in the table body. Sep 29 '12 at 22:18
  • @nagylzs TeX informs you if the longtable is not yet stable. Don't worry too much: during document preparation, you run frequently LaTeX, so this is a minor problem.
    – egreg
    Sep 29 '12 at 22:27

The headers and footers of a longtable cannot be typeset correctly at the first run, but also the rows: for saving memory and avoiding overflows, longtable processes the table dividing it into chunks and annotating in the .aux file the column widths, so that in the next LaTeX run they can be fixed.

Depending on the table, two or three runs may be needed. If a new run is needed, LaTeX will print in the .log file a couple of warnings. The first

Package longtable Warning: Column widths have changed
(longtable)                in table 1 on input line 55.

when the table is typeset, the second

Package longtable Warning: Table widths have changed. Rerun LaTeX.

at the end of the run. In this way the user is informed about the problem.

This shows also the importance of the .aux file that mustn't be deleted after a run, because it contains basic information for the next run (cross references, for instance). Only in a few cases, due to some kinds of errors in the input, the .aux file can become corrupt. This usually shows with weird errors in the early stages of the LaTeX run. When the compiler raises a very weird error, one of the strategies is indeed removing the .aux file; but this is more the exception than the rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.