2

Similar to this question but not sure if mine is exactly the same???

I am trying to center just the first row of cells in tabularx environment, leaving the rest left/justified.

\documentclass{report}
\usepackage{tabularx}
\begin{document}
    \begin{tabularx}{\textwidth}{|X|X|X|}
        \hline
        \centering \textbf{a} & \centering \textbf{b} & \textbf{c} \\
        \hline
        a & b & c \\
        \hline
    \end{tabularx}
\end{document}

When I add \centering to the last cell in the 1st row, it throws

Misplaced \noalign. \end{tabularx}

I know I can circumvent that by adding $\;\;\;\;\;\;\;\;$ in front of the cell content to approximately center it, but it's ugly.

  • 3
    try \centering \textbf{a} & \centering \textbf{b} & \centering\arraybackslash\textbf{c} but better is use multicolumn{1}{c}{...} environment ... – Zarko Oct 27 '16 at 20:32
3

\centering redefines \\, thus it won't no longer work as end of line in a tabular. But there is \tabularnewline:

\documentclass{report}
\usepackage{tabularx}
\begin{document}
    \noindent
    \begin{tabularx}{\textwidth}{|X|X|X|}
        \hline
        \centering \textbf{a} & \centering \textbf{b} & \centering \textbf{c}
        \tabularnewline
        \hline
        a & b & c \\
        \hline
    \end{tabularx}
\end{document}

Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.