1

I have a simple long table, for which I want multiple columns to be centered:

\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}

However, fi I want the last column to be \centered as well, this gives an error abd the output is messed up:

Extra alignment tab has been changed to \cr. Wind direction &

1
  • I want to have fixed widths Commented Jul 24, 2017 at 11:58

1 Answer 1

2
% 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}

will do the trick.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .