Misplaced alignment tab character & in longtable

alignmentlongtable

I am trying to make a table; and this I use for centering headings;

\NewExpandableDocumentCommand\mcc{m}{\multicolumn{1}{c}{#1}}

I have the following table using longtable package;

    \begin{longtable}{l l l l l l}
    \centering
    \caption{Quality scores assigned to the papers selected for inclusion.}
    \label{T:quality_scores}
    \hline
    \mcc{Paper reference} & \mcc{Objectives} & \mcc{Results evaluation} & \mcc{Research Process} & \mcc{Comparisons} & \mcc{Sum}  \\
    \hline
    [1] & 0.0 & 1.0 & 1.0 & 1.0 & 3.0 \\ 
    [2] & 0.0 & 1.0 & 1.0 & 0.5 & 2.5 \\ 
    [3] & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    [4] & 0.0 & 0.5 & 0.5 & 1.0 & 2.0 \\ 
    [5] & 0.5 & 1.0 & 1.0 & 1.0 & 3.5 \\ 
    [6] & 0.5 & 1.0 & 0.0 & 1.0 & 2.5 \\ 
    [7] & 1.0 & 0.0 & 1.0 & 0.0 & 2.0 \\ 
    [8] & 1.0 & 0.5 & 1.0 & 1.0 & 3.5 \\ 
    [9] & 1.0 & 0.5 & 1.0 & 1.0 & 3.5 \\ 
    [10] & 0.5 & 1.0 & 1.0 & 1.0 & 3.5 \\ 
    [11] & 1.0 & 0.5 & 1.0 & 1.0 & 3.5 \\ 
    [12] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [13] & 0.5 & 0.5 & 1.0 & 0.0 & 2.0 \\ 
    [14] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [15] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [16] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [17] & 1.0 & 0.5 & 0.5 & 0.0 & 2.0 \\ 
    [18] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [19] & 1.0 & 1.0 & 1.0 & 0.0 & 3.0 \\ 
    [20] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [21] & 1.0 & 0.0 & 0.5 & 1.0 & 2.5 \\ 
    [22] & 0.5 & 0.5 & 0.5 & 0.5 & 2.0 \\ 
    [23] & 1.0 & 1.0 & 0.5 & 0.5 & 3.0 \\ 
    [24] & 1.0 & 0.5 & 1.0 & 0.0 & 2.5 \\ 
    [25] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [26] & 1.0 & 1.0 & 1.0 & 0.5 & 3.5 \\ 
    [27] & 0.5 & 0.5 & 0.0 & 1.0 & 2.0 \\ 
    [28] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [29] & 0.5 & 0.0 & 1.0 & 1.0 & 2.5 \\ 
    [30] & 1.0 & 1.0 & 0.0 & 0.0 & 2.0 \\ 
    [31] & 1.0 & 1.0 & 1.0 & 0.0 & 3.0 \\ 
    [32] & 1.0 & 0.0 & 0.5 & 0.5 & 2.0 \\ 
    [33] & 1.0 & 1.0 & 1.0 & 0.5 & 3.5 \\ 
    [34] & 0.5 & 0.0 & 1.0 & 1.0 & 2.5 \\ 
    [35] & 1.0 & 1.0 & 1.0 & 0.5 & 3.5 \\ 
    [36] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [37] & 0.5 & 1.0 & 1.0 & 0.5 & 3.0 \\ 
    [38] & 0.5 & 0.5 & 1.0 & 0.0 & 2.0 \\ 
    [39] & 1.0 & 0.0 & 1.0 & 0.0 & 2.0 \\ 
    [40] & 0.5 & 1.0 & 1.0 & 1.0 & 3.5 \\ 
    [41] & 0.5 & 0.5 & 1.0 & 1.0 & 3.0 \\ 
    [42] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [43] & 0.5 & 0.0 & 1.0 & 1.0 & 2.5 \\ 
    [44] & 0.5 & 1.0 & 0.0 & 1.0 & 2.5 \\ 
    [45] & 1.0 & 0.5 & 1.0 & 0.5 & 3.0 \\ 
    [46] & 0.5 & 1.0 & 0.5 & 0.0 & 2.0 \\ 
    [47] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [48] & 1.0 & 1.0 & 0.5 & 1.0 & 3.5 \\ 
    [49] & 1.0 & 0.5 & 1.0 & 0.5 & 3.0 \\ 
    [50] & 0.5 & 1.0 & 0.5 & 0.5 & 2.5 \\ 
    [51] & 1.0 & 1.0 & 0.5 & 0.0 & 2.5 \\ 
    [52] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [53] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [54] & 1.0 & 1.0 & 0.5 & 0.5 & 3.0 \\ 
    [55] & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    [56] & 0.0 & 1.0 & 1.0 & 1.0 & 3.0 \\ 
    [57] & 1.0 & 0.0 & 0.5 & 0.5 & 2.0 \\ 
    [58] & 0.0 & 1.0 & 0.0 & 1.0 & 2.0 \\ 
    [59] & 1.0 & 1.0 & 0.0 & 0.5 & 2.5 \\ 
    [60] & 1.0 & 1.0 & 0.5 & 0.5 & 3.0 \\ 
    [61] & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    [62] & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    [63] & 1.0 & 0.5 & 0.0 & 0.5 & 2.0 \\ 
    [64] & 1.0 & 0.5 & 0.5 & 0.5 & 2.5 \\ 
    [65] & 1.0 & 0.0 & 0.5 & 1.0 & 2.5 \\ 
    [66] & 1.0 & 0.5 & 0.5 & 0.5 & 2.5 \\ 
    [67] & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    [68] & 0.5 & 1.0 & 0.5 & 0.5 & 2.5 \\
    \hline
    \end{longtable}

And got this error Misplaced alignment tab character &. Any suggestions?

Best Answer

First of please always post full minimal examples, not these sniplets where we have to add stuff in order to test your code.

That being said here are some observations.

  • You're not getting an error about alignment tab character & that is an accumulative error. Always look at the first error.

The first error I get when adding the code into the smallest of test files is

! Misplaced \noalign

coming from the \caption line, but it is actually coming from \centering. So we remove it.

The error when then get is

! Misplaced \noalign.
\hline ->\noalign 
                  {\ifnum 0=`}\fi \penalty \@M \futurelet \@let@token \LT@@h...

This is because inside longtable the \caption macro is redefined as a type of \multicolumn macro. And thus this row has to be ended by \\ before the \hline. So we add \\ after the \label.

The next error we then get is

! Illegal unit of measure (pt inserted).
<to be read again> 
                   >
l.15     [2]
             & 0.0 & 1.0 & 1.0 & 0.5 & 2.5 \\

This is coming from the \\ on the [1] row. \\ can take an optional argument in [...] sadly here \\ <linebreak> [2] is seen as \\[2] and that is not an allowed option for \\ hence the error.

Solution: write all [<num>] as {[<num>] then the argument parser for \\ cannot see the [ and stops looking for it.

Now the code compiles.

Two suggestions, use the rules from booktabs (there are three) instead of \hline, it looks better. Use the head and foot part of the longtable configuration to get good headers and footers on the table when it is brokwn across pages (for example automatically duplicating the header after a page break). I will leave these to you.

Here is working code

\documentclass[a4paper]{article}
\NewExpandableDocumentCommand\mcc{m}{\multicolumn{1}{c}{#1}}
\usepackage{longtable}

\begin{document}

\begin{longtable}{l l l l l l}
  \caption{Quality scores assigned to the papers selected for inclusion.}
  \label{T:quality_scores}
  \\
    \hline
    \mcc{Paper reference} & \mcc{Objectives} & \mcc{Results evaluation} & \mcc{Research Process} & \mcc{Comparisons} & \mcc{Sum}  \\
    \hline
    {[1]} & 0.0 & 1.0 & 1.0 & 1.0 & 3.0 \\ 
    {[2]} & 0.0 & 1.0 & 1.0 & 0.5 & 2.5 \\ 
    {[3]} & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    {[4]} & 0.0 & 0.5 & 0.5 & 1.0 & 2.0 \\ 
    {[5]} & 0.5 & 1.0 & 1.0 & 1.0 & 3.5 \\ 
    {[6]} & 0.5 & 1.0 & 0.0 & 1.0 & 2.5 \\ 
    {[7]} & 1.0 & 0.0 & 1.0 & 0.0 & 2.0 \\ 
    {[8]} & 1.0 & 0.5 & 1.0 & 1.0 & 3.5 \\ 
    {[9]} & 1.0 & 0.5 & 1.0 & 1.0 &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 & 2.5 \\ 
    {[60]} & 1.0 & 1.0 & 0.5 & 0.5 & 3.0 \\ 
    {[61]} & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    {[62]} & 1.0 & 1.0 & 1.0 & 1.0 & 4.0 \\ 
    {[63]} & 1.0 & 0.5 & 0.0 & 0.5 & 2.0 \\ 
    {[64]} & 1.0 & 0.5 & 0.5 & 0.5 & 2.5 \\ 
    {[65]} & 1.0 & 0.0 & 0.5 & 1.0 & 2.5 \\ 
    {[66]} & 1.0 & 0.5 & 0.5 & 0.5 & 2.5 \\ 
    {[67]} & 0.5 & 1.0 & 0.5 & 1.0 & 3.0 \\ 
    {[68]} & 0.5 & 1.0 & 0.5 & 0.5 & 2.5 \\
    \hline
    \end{longtable}


\end{document}