Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a column in a tabular with column specifier 'p' and centred text. I have tried to achieve this using the example below.

\documentclass{article}

\usepackage{array}

\begin{document}

\begin{table}
  \begin{tabular}{c l >{\centering}p{2cm}}
    a & b & c \\
    a & b & c 
  \end{tabular}
\end{table}

\end{document}

Why does this create the following error, and what is the correct way to do this?

! Extra alignment tab has been changed to \cr.
<recently read> \endtemplate 

l.10     a &
             b & c
You have given more \span or & marks than there were
in the preamble to the \halign or \valign now in progress.
So I'll assume that you meant to type \cr instead.

I'm using Miktex 2.9

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted
\documentclass{article}    
\usepackage{array}
\begin{document}

  \begin{tabular}{ c l >{\centering\arraybackslash}p{2cm}}
    a & b & c \\
    a & b & c 
  \end{tabular}

\end{document}

\centering redefines the double backslash. However, a better choice is to use

\documentclass{article}    
\usepackage{array,ragged2e}
\begin{document}

  \begin{tabular}{ c l >{\Centering}p{2cm}}
    a & b & c \\
    a & b & c 
  \end{tabular}

\end{document}
share|improve this answer
    
Thanks, since you answered I have also discovered another option would be to use the \tabularnewline command instead of \\ in the table but your solution is better. –  crobar Feb 13 '12 at 14:22
    
tabularnewline does nearly the same as \arraybackslash once –  Herbert Feb 13 '12 at 15:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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