I have a minimal LaTeX document like this:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{ X | X }
\centering A & B \\ \hline
1.0 & 2.0 \\
\end{tabularx}
\end{document}
I would like to center the table headers but left-align the columns. However, when I add \centering to the B header, like this:
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{ X | X }
\centering A & \centering B \\ \hline
1.0 & 2.0 \\
\end{tabularx}
\end{document}
I get this error:
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8 \end{tabularx}
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.8 \end{tabularx}
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8 \end{tabularx}
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.8 \end{tabularx}
! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \hrule \@height \arrayrulewidth \futurelet...
l.8 \end{tabularx}
! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate
l.8 \end{tabularx}


tabularxandXcolumns – Werner Feb 20 '19 at 18:58