Another way to get a ! Extra alignment tab has been changed to \cr
error is to use an alignment command (\centering
, \raggedleft
, \raggedright
) in the last row of a tabular
environment (when using p{}
formatting, of course).
For example, this code will give an error:
\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|}
A & \centering B \\
C & D \\
\end{tabular}
But this code will not:
\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|}
\centering A & B \\
\centering C & D \\
\end{tabular}
We can use the environment center
to overcome this problem, with the caveat that we will have extra vertical spaces. (needless to say, you may change to c
column formatting, if you are willing to give up width control ;))
A quick fix for the problem is to add a zero-width column, e.g., p{0pt}
Quick fix solution:
\begin{tabular}{|p{0.2\textwidth}|p{0.2\textwidth}|p{0pt}}
\centering A & \centering B &\\
\raggedleft C & \raggedright D &\\
\end{tabular}