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 &

  • I want to have fixed widths – Joost Döbken Jul 24 '17 at 11:58
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.

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.