我有一个简单的长表,我想让多个列居中:
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{longtable}[c]{
p{0.47\linewidth}
*3{>{\centering}p{0.08\linewidth}}
>{}p{0.08\linewidth}
}
\rowcolor{red}
& \multicolumn{1}{c}{\textbf{\color{white}00:00}}
& \multicolumn{1}{c}{\textbf{\color{white}06:00}}
& \multicolumn{1}{c}{\textbf{\color{white}12:00}}
& \multicolumn{1}{c}{\textbf{\color{white}18:00}}
\\
\endhead
Wind speed(m/s) & 9 & 8 & 9 & 7 \\
Wind direction & W & W & SW & SW \\
\hline
\end{longtable}
\end{document}
但是,如果我希望最后一列也如此\centered
,则会出现错误,并且输出也会混乱:
额外的对齐标签已更改为 \cr。风向 &
答案1
% arara: pdflatex
\documentclass{article}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{longtable}
\begin{document}
\begin{longtable}[c]{%
p{0.47\linewidth}
*4{>{\centering\arraybackslash}p{0.08\linewidth}}
}
\rowcolor{red}
& \textbf{\color{white}00:00}
& \textbf{\color{white}06:00}
& \textbf{\color{white}12:00}
& \textbf{\color{white}18:00}
\\
\endhead
Wind speed (m/s) & 9 & 8 & 9 & 7 \\
Wind direction & W & W & SW & SW \\
\bottomrule
\end{longtable}
\end{document}
就可以了。