\documentclass[12pt, a4paper, UTF8, scheme = plain, twoside]{ctexart}
%%
%%
\usepackage{amsmath}
\usepackage{booktabs,array}
\usepackage[top=0.5cm,left=0.5cm,right=0.5cm,bottom=1.68cm]{geometry}
\usepackage{graphicx}
%%
%%
\begin{document}
%%
%%
\begin{center}
\renewcommand*{\arraystretch}{1.2}
\Large
\begin{tabular}{| >{\centering}p{5.8cm} | >{\centering}p{1.8cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
c | % works with c|
}
\toprule
\textbf{PaperName} &
\textbf{Page} &
\textbf{A} &
\textbf{B} &
\textbf{C} &
\textbf{D} &
\textbf{E} \\
\midrule
\verb=9709_s21_ms_13= & 1 & 59 & 51 & 42 & 32 & 22 \\
\verb=9709_s21_ms_12= & 17 & 63 & 54 & 44 & 34 & 23 \\
\verb=9709_s21_ms_11= & 33 & 61 & 50 & 41 & 31 & 21 \\
\verb=9709_s20_ms_13= & 49 & & & & & \\
\verb=9709_s20_ms_12= & 67 & & & & & \\
\verb=9709_s20_ms_11= & 81 & & & & & \\
\verb=9709_s19_ms_13= & 97 & 62 & 54 & 44 & 34 & 24 \\
\verb=9709_s19_ms_12= & 111 & 65 & 54 & 43 & 31 & 19 \\
\verb=9709_s19_ms_11= & 127 & 65 & 57 & 47 & 37 & 28 \\
\verb=9709_s18_ms_13= & 146 & 62 & 55 & 45 & 35 & 25 \\
\verb=9709_s18_ms_12= & 164 & 62 & 52 & 42 & 32 & 21 \\
\verb=9709_s18_ms_11= & 182 & 62 & 54 & 44 & 34 & 24 \\
\verb=9709_s17_ms_13= & 199 & 49 & 41 & 32 & 23 & 13 \\
\verb=9709_s17_ms_12= & 214 & 51 & 42 & 31 & 21 & 10 \\
\verb=9709_s17_ms_11= & 232 & 55 & 46 & 37 & 28 & 18 \\
\bottomrule
\end{tabular}%
\end{center}
%%
\end{document}
对于最后一列,如果我使用
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} |
>{\centering}p{1.0cm} | % works with c|
相反,它会给我一个错误......
\midrule ->\noalign {\ifnum 0=`}\fi @aboverulesep =\aboverulesep \global @...
为什么?我该如何修复?
答案1
\centering
重新定义\\
为居中换行符,打破了tabular
使用,你可以用它\centering\arraybackslash
来恢复数组/表格\\
另外,可能更好的方法是,因为看起来您的表格单元格并不是真正的多行段落,c
因此请使用固定宽度形式,wc{1cm}
而不是p{1cm}
针对所有列。(需要array
不太旧的软件包)
答案2
用于>{\centering\arraybackslash}p{1cm}
最后一列或者让 TeX 进行计算:
\documentclass[
12pt,
a4paper,
UTF8,
scheme = plain,
twoside,
fontset = windows % because otherwise it doesn't work on macOS
]{ctexart}
\usepackage{amsmath}
\usepackage{booktabs,array}
\usepackage[
top=0.5cm,
left=0.5cm,
right=0.5cm,
bottom=1.68cm,
showframe % <--- remove from production version
]{geometry}
\begin{document}
\begin{center}
\renewcommand*{\arraystretch}{1.2}
\Large
\begin{tabular*}{0.8\textwidth}{
@{\hspace{\tabcolsep}\extracolsep{\fill}}
*{7}{c}
@{\hspace{\tabcolsep}}
}
\toprule
\textbf{PaperName} &
\textbf{Page} &
\textbf{A} &
\textbf{B} &
\textbf{C} &
\textbf{D} &
\textbf{E} \\
\midrule
\verb=9709_s21_ms_13= & 1 & 59 & 51 & 42 & 32 & 22 \\
\verb=9709_s21_ms_12= & 17 & 63 & 54 & 44 & 34 & 23 \\
\verb=9709_s21_ms_11= & 33 & 61 & 50 & 41 & 31 & 21 \\
\verb=9709_s20_ms_13= & 49 & & & & & \\
\verb=9709_s20_ms_12= & 67 & & & & & \\
\verb=9709_s20_ms_11= & 81 & & & & & \\
\verb=9709_s19_ms_13= & 97 & 62 & 54 & 44 & 34 & 24 \\
\verb=9709_s19_ms_12= & 111 & 65 & 54 & 43 & 31 & 19 \\
\verb=9709_s19_ms_11= & 127 & 65 & 57 & 47 & 37 & 28 \\
\verb=9709_s18_ms_13= & 146 & 62 & 55 & 45 & 35 & 25 \\
\verb=9709_s18_ms_12= & 164 & 62 & 52 & 42 & 32 & 21 \\
\verb=9709_s18_ms_11= & 182 & 62 & 54 & 44 & 34 & 24 \\
\verb=9709_s17_ms_13= & 199 & 49 & 41 & 32 & 23 & 13 \\
\verb=9709_s17_ms_12= & 214 & 51 & 42 & 31 & 21 & 10 \\
\verb=9709_s17_ms_11= & 232 & 55 & 46 & 37 & 28 & 18 \\
\bottomrule
\end{tabular*}
\end{center}
\end{document}
如果使用\toprule
、\midrule
和,请不要添加垂直线\bottomrule
。实际上,最好绝不在表格中使用垂直线。