我想在表格中创建一个列,列说明符为“p”,文本居中。我尝试使用以下示例来实现这一点。
\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}
为什么这会导致以下错误?正确的方法是什么?
! 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.
我正在使用 Miktex 2.9
答案1
\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
重新定义双反斜杠。不过,更好的选择是使用
\documentclass{article}
\usepackage{array,ragged2e}
\begin{document}
\begin{tabular}{ c l >{\Centering}p{2cm}}
a & b & c \\
a & b & c
\end{tabular}
\end{document}