我一直在尝试获取具有指定列宽和居中文本的长表。我找到了一种方法来做到这一点(>{\centering}p{1cm}
),这种方法一直有效,直到我将居中应用于最后一列,此时我收到错误(! Extra alignment tab has been changed to \cr.
)。我不确定为什么会发生此错误。
以下是没有错误的 MWE:
\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}
错误如下。(导致错误的代码是>{\centering}p{1.5cm}
最终的列定义)。
\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}
任何帮助,将不胜感激。