I have had this problem before (sort of) - it's related to this question I asked previously.
Basically, I am having trouble with my table headings. I want the headings to be bold and centered regardless of the alignment of the text in the columns below. I have defined a new command head
to do this, which seems to be working fine except for the last column. If I use head
in place of \bfseries
in the last column I get an error
! Misplaced \noalign. \cmidrule ->\noalign
{\ifnum 0=`}\fi \@ifnextchar [{\@cmidrule }{\@cmidrule ... l.37 \cmidrule
(r){1-1} \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-...
I have read various things about "mislpaced \noalign" complaints coming from things to do with backslashes, but I don't see why that last column should behave any differently from the others.
I have tried to get the text centered by adding a \centering
instead but the required \par
messes up the vertical alignment. Anyway, I don't see that I should have to do something different, but I can't see what I've done wrong?
\documentclass[11pt, a4paper, twoside, fleqn]{report}
\usepackage[showframe]{geometry}
\makeatletter
\g@addto@macro\@floatboxreset\centering % automatically center floats
\makeatother
%Table formatting
%------------------------------
\usepackage{array}
\usepackage{booktabs}
\renewcommand{\arraystretch}{1.5}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcommand{\head}[1]{\centering\textbf{#1}}
%Definitions of useful shortcuts (e.g. to add matrix formatting)
%---------------------------------------------------------------
\begin{document}
\begin{table}
\footnotesize
%%%\addtolength{\tabcolsep}{-0.6pt}
\begin{tabular}{ @{} L{1.5cm} C{1.5cm} C{2cm} C{1.5cm} C{2cm} L{4cm} @{}}
\toprule
\head{Head} & \head{Stuff} & \head{Things} & \head{Stuff} & \head{Things} & \bfseries Stuff Things \\
\head{Head} & \head{Stuff} & \head{Things} & \head{Stuff} & \head{Things} & {\head{Stuff Things}} \\
\cmidrule(r){1-1} \cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-6} % no "r" here because it's the last
\multicolumn{2}{@{}l}{\bfseries Subheading}\\% \addlinespce
text & text & some much longer text & text & some much longer text & some even longer even longer even longer text \\
\bottomrule
\end{tabular}
\caption{And here's the caption}
\end{table}
\end{document}
Update:
\listfiles
gives the following:
report.cls 2005/09/16 v1.4f Standard LaTeX document class<br>
fleqn.clo 1998/08/17 v1.1c Standard LaTeX option (flush left equations)<br>
size11.clo 2005/09/16 v1.4f Standard LaTeX file (size option)<br>
array.sty 2005/08/23 v2.4b Tabular extension package (FMi)<br>
booktabs.sty 2005/03/16 v1.6180 publication quality tables
We are well aware that our latex is very very out of date! Something I am trying to get fixed. I can overwrite locally if necessary.
Just to be clear, the compilation problem arises if I replace
& \head{Stuff} & \head{Things} & \head{Stuff} & \head{Things} & {\bfseries Stuff Things} \\
with
& \head{Stuff} & \head{Things} & \head{Stuff} & \head{Things} & \head{Stuff Things} \\
Update 2
I've edited my code above to make it more obvious that this problem is only arising the last column (the first column is L aligned too, but the \head
command is centering my heading).
As per Johannes_B's suggestion, if I add an extra set of braces to the last column
& \head{Stuff} & \head{Things} & \head{Stuff} & \head{Things} & {\head{Stuff Things}} \\
the compilation problem goes away but the final column heading remains left aligned:
Using makecell
and in particular thead
seems to work fine, but I'd still like to know what's wrong with my code! Can anyone tell me why I am getting this behaviour?
\let\newline\\
? Remove them and it compiles just fine\arraybackslash
takes care of that.\arraybackslash
in your definition.