1

I am having trouble using \midrule in a latex longtable along with brackets. For example, here is my latex document (test.tex):

\documentclass[a4paper]{article}\usepackage[]{graphicx}\usepackage[]{color}
\usepackage{longtable}
\usepackage{booktabs}

\begin{document}

\begin{longtable}{|l|l|}
\caption{} \\
  \toprule
 test & estimate\\
  \midrule
  (Intercept) & 10.000 \\
  test & 20.000 \\
   \bottomrule
\end{longtable}

\end{document}

When running pdflatex on this file:

pdflatex test.tex

I run into these errors:

! Undefined control sequence.
<argument> ...al \expandafter \let \cmrsideswitch
                                                 \@tempa \fi \fi
l.12   (Intercept)
                  & 10.000 \\

Removing the brackets fixes the issue. And interestingly switching the order of the 2 rows works too [i.e. the (Intercept) row as the second row). I can't figure out what is wrong. Has anyone encountered this?

TinyHeero
  • 580
  • 1
  • 4
  • 18
  • Are you creating a results table out of R? If so, perhaps you should be using one of the automatic table generation tools like stargazer or xtable. – Thomas Jan 01 '15 at 09:20
  • I have same problem with table generated from pandoc, this time the bracket is at the beginning of row (just after \toprule). – Vladimir Still Jan 01 '15 at 16:57
  • Yes I am actually using knitr and the R package xtable to generate these tables. I just stripped it down to a minimalistic example. But this code was generated. – TinyHeero Jan 01 '15 at 19:21

1 Answers1

1

OK, so I had the same problem with code generated from Pandoc (with bracket after \toprule), I fixed it by using \toprule{} instead, it seems that toprule eats the bracket otherwise. Maybe this will help you.

Another possibilty is to put empty \hbox{} before the opening bracket, which I used, since I could not modify tex produced by pandoc (but pandoc is capable of parsing latex snippets in markdown).

Vladimir Still
  • 634
  • 3
  • 17
  • You're right! By replacing \midrule with \midrule{}, pdflatex worked. Why does that even work? – TinyHeero Jan 01 '15 at 19:44
  • 1
    My understanding is, that when latex command takes mandatory argument, it can be either some kind of "single token argument" (I'm not sure what the right name would be), or more complex argument in braces. If you don't provide the mandatory argument, the command will just use first thing it finds after its use. And for some reason rule commands handle opening bracket wrong. But this is just my speculation. – Vladimir Still Jan 01 '15 at 20:15