latexlongtable

Using the booktabs \midrule and with brackets


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?


Solution

  • 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).