0

I have been trying to get a long table with specified column widths and centered text. I found away to do this (>{\centering}p{1cm}) which works until I apply centering to the last column, at which point I receive errors (! Extra alignment tab has been changed to \cr.). I'm not sure why this error is happening.

Here is a MWE without the error:

\documentclass[12pt,a4paper,hidelinks,twoside]{report}
\raggedbottom
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[greek,spanish,english]{babel}
\usepackage{textgreek}
\usepackage[version=3]{mhchem}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{amsmath, amsfonts, amssymb, pifont, float, color, url}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex, plainpages=false, pdfpagelabels, bookmarks=true]{hyperref}
\usepackage{fancyhdr}
\usepackage[center,font={it,small},skip=5pt]{caption}
\usepackage{tabularx}
\usepackage{lscape}
\usepackage{longtable}

\begin{document}
\begingroup
\begin{landscape}
\begin{center}
\begin{longtable}{>{\centering}p{3cm}>{\centering}p{1.5cm}>{\centering}p{2.5cm}>   {\centering}p{1.5cm}>{\centering}p{3cm}>{\centering}p{1.5cm}>{\centering}p{1.7cm}>{\centering}p{1.5cm}>{\centering}p{1.7cm}p{1.5cm}}
\hline\\[-2ex]
Molecule & $Log S$ &  $Log S$ & Error & $Log S$ & Error & $Log S$ & Error & $Log S$ & Error\\
& Exp &  3DRISM/UC & & SMD(M06-2X) & & SMD(HF) & & PCM(HF)& \\
\hline\hline\\[-2ex]
\endfirsthead
\multicolumn{5}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline\\[-2ex]
Molecule & $Log S$ &  $Log S$ & Error & $Log S$ & Error & $Log S$ & Error & $Log S$ &  Error\\
& Exp &  3DRISM/UC & & SMD(M062X) & & SMD(HF) & & PCM(HF)& \\
\hline\hline\\[-2ex]
\endhead
\hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
ALOPUR&-2.26&-0.06&-2.2&-1.8&-0.46&0.42&-2.68&-1.04&-1.22\\
AMBNAC04&-1.37&-0.22&-1.15&-2.02&0.65&-1.03&-0.34&-2.34&0.97\\
AMXBPM10&-2.95&-3.63&0.68&-7.62&4.67&-5.00&2.88&-10.45&7.5\\
BENZAC02&-1.58&-1.02&-0.56&-3.05&1.47&-1.9&0.32&-2.55&0.97\\
BZAMID02&-0.95&0.87&-1.82&-1.27&0.32&-0.1&-0.85&-1.61&0.66\\
SALIAC&-1.93&-0.91&-1.02&-2.49&0.56&-1.37&-0.56&-2.05&0.12\\\newpage
SIKLIH01&-5.46&-6.28&0.82&-7.67&2.21&-6.1&0.64&-10.13&4.67\\
XYANAC&-6.74&-7.17&0.43&-9.31&2.57&-8.78&2.04&-10.53&3.79\\[1ex]
\hline\\[-2ex]
$R^{2}$ && 0.72 && 0.74 && 0.71 && 0.55&\\
$\sigma$& 1.79 & 1.43 && 1.82 && 2.03 && 2.54&\\
Bias&& -0.23 && 1.46 && -0.05 && 2.21&\\
RMSE&& 1.45 && 2.33 && 2.03 && 3.40&\\[1ex]
\hline
\caption{some data.}\label{table}
\end{longtable}
\end{center}
\end{landscape}
\endgroup
\end{document}

With the error is below. (Code causing error is >{\centering}p{1.5cm} the final column definition).

\documentclass[12pt,a4paper,hidelinks,twoside]{report}
\raggedbottom
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[greek,spanish,english]{babel}
\usepackage{textgreek}
\usepackage[version=3]{mhchem}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{amsmath, amsfonts, amssymb, pifont, float, color, url}
\usepackage[pdftex]{graphicx}
\usepackage[pdftex, plainpages=false, pdfpagelabels, bookmarks=true]{hyperref}
\usepackage{fancyhdr}
\usepackage[center,font={it,small},skip=5pt]{caption}
\usepackage{tabularx}
\usepackage{lscape}
\usepackage{longtable}

\begin{document}
\begingroup
\begin{landscape}
\begin{center}
\begin{longtable}{>{\centering}p{3cm}>{\centering}p{1.5cm}>{\centering}p{2.5cm}>   {\centering}p{1.5cm}>{\centering}p{3cm}>{\centering}p{1.5cm}>{\centering}p{1.7cm}>{\centering}p{1.5cm}>{\centering}p{1.7cm}>{\centering}p{1.5cm}}
\hline\\[-2ex]
Molecule & $Log S$ &  $Log S$ & Error & $Log S$ & Error & $Log S$ & Error & $Log S$ & Error\\
& Exp &  3DRISM/UC & & SMD(M06-2X) & & SMD(HF) & & PCM(HF)& \\
\hline\hline\\[-2ex]
\endfirsthead
\multicolumn{5}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline\\[-2ex]
Molecule & $Log S$ &  $Log S$ & Error & $Log S$ & Error & $Log S$ & Error & $Log S$ &  Error\\
& Exp &  3DRISM/UC & & SMD(M062X) & & SMD(HF) & & PCM(HF)& \\
\hline\hline\\[-2ex]
\endhead
\hline \multicolumn{5}{r}{\textit{Continued on next page}} \\
\endfoot
\endlastfoot
ALOPUR&-2.26&-0.06&-2.2&-1.8&-0.46&0.42&-2.68&-1.04&-1.22\\
AMBNAC04&-1.37&-0.22&-1.15&-2.02&0.65&-1.03&-0.34&-2.34&0.97\\
AMXBPM10&-2.95&-3.63&0.68&-7.62&4.67&-5.00&2.88&-10.45&7.5\\
BENZAC02&-1.58&-1.02&-0.56&-3.05&1.47&-1.9&0.32&-2.55&0.97\\
BZAMID02&-0.95&0.87&-1.82&-1.27&0.32&-0.1&-0.85&-1.61&0.66\\
SALIAC&-1.93&-0.91&-1.02&-2.49&0.56&-1.37&-0.56&-2.05&0.12\\\newpage
SIKLIH01&-5.46&-6.28&0.82&-7.67&2.21&-6.1&0.64&-10.13&4.67\\
XYANAC&-6.74&-7.17&0.43&-9.31&2.57&-8.78&2.04&-10.53&3.79\\[1ex]
\hline\\[-2ex]
$R^{2}$ && 0.72 && 0.74 && 0.71 && 0.55&\\
$\sigma$& 1.79 & 1.43 && 1.82 && 2.03 && 2.54&\\
Bias&& -0.23 && 1.46 && -0.05 && 2.21&\\
RMSE&& 1.45 && 2.33 && 2.03 && 3.40&\\[1ex]
\hline
\caption{some data.}\label{table}
\end{longtable}
\end{center}
\end{landscape}
\endgroup
\end{document}

Any help would be appreciated.

marked as duplicate by LaRiFaRi, Nico Boni, David Carlisle, Claudio Fiandrino, Malipivo Sep 9 '14 at 9:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    you need >{\centering\arraybackslash}p{1.5cm} – Nico Boni Sep 9 '14 at 9:24
  • for the very last one... The error is that \centering redefines the meaning of \\. Please read the package documentation of array for more information. – LaRiFaRi Sep 9 '14 at 9:26
  • this must be a duplicate of something... – Nico Boni Sep 9 '14 at 9:28
  • @James: Your table would look much better if you used the S column type (from the siunitx package). You wouldn't have this problem then, as everything is automatically centred. I have a code for that, but I can't post it as the question is closed. Is there a place where I can send it? – Bernard Sep 9 '14 at 10:47
  • @dcmst thanks for your answer that solves it. – James Sep 9 '14 at 14:06