我有一张跨越整个页面的表格(为了与我拥有的其他表格保持一致),但是这张表格中有垂直线,而让表格跨越整个页面会导致垂直线不居中:
我怎样才能使垂直线在它们分隔的列之间水平居中?删除这些线不是一个选择,我宁愿不使用其他包(如果可能的话)。
\documentclass{article}
\RequirePackage[top=2.54cm, bottom=2.54cm, left=3.05cm, right=2.54cm]{geometry}
\usepackage{booktabs}
\begin{document}
\newcommand{\mlc}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}% http://tex.stackexchange.com/a/19678
\begin{table}[t]
\centering
\caption{a table with uncentered vertical lines }
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}}cc|ccc||c} %
\toprule
\multicolumn{2}{c}{ } & \multicolumn{4}{c}{cut-off} \\ \cline{3-6} \\
\mlc{Various stuff\\(MeV)} & \# of data & A & B & C & \mlc{Ref. [bleh] \\ at B } \\
\midrule
$np$ &&&&&\\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\midrule
$pp$ &&&&&\\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
答案1
tabularx
我建议使用和来编写此代码makecell
。Makecell 允许在表格单元格中换行,使用\setcellgapes
和\makegapedcells
命令对单元格进行垂直填充,以及使用可变粗细的线条。我不确定您是否希望在第二行中使用垂直线。如果需要,它们很容易添加。此外,我加载了caption
标题和表格之间正确的垂直间距。
\documentclass{article}
\RequirePackage[vmargin=2.54cm, left=3.05cm, right=2.54cm]{geometry}
\usepackage{caption}
\usepackage{makecell, tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}p{#1}}
\setcellgapes{3pt}
\begin{document}
\begin{table}[t]
\centering
\makegapedcells
\caption{a table with centred vertical lines }
\begin{tabularx}{\linewidth}{XX|XXX||X} %
\Xhline{0.08em}\noalign{\vskip1ex}
\multicolumn{2}{c}{} & \multicolumn{4}{c}{cut-off} \\[1ex]
\Xcline{3-6}{0.05em}
\makecell{Various stuff \\(MeV)} & \multicolumn{1}{c}{\# of data} & A & B & \multicolumn{1}{c}{C} & \makecell{Ref. [bleh] \\ at B } \\
\Xhline{0.05em}
$np$ & & & & & \\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\Xhline{0.05em}
$pp$ & & & & & \\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\Xhline{0.08em}
\end{tabularx}
\end{table}
\end{document}
答案2
据我所知,最好的办法是:
你的教授喜欢这个设计吗?对于上表,我使用了包makecell
、multirow
和tabu
:
\documentclass{article}
\usepackage[top=2.54cm, bottom=2.54cm, left=3.05cm, right=2.54cm]{geometry}
\usepackage{makecell,multirow,tabu}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}}
\newcommand\mrc[2]{\multirowcell{#1}[0pt][c]{#2\strut}}
\begin{document}
%---------------------------------------------------------------%
\begin{table}
\abovetabulinesep=2mm
\belowtabulinesep=2mm
\begin{tabu}to \linewidth {*2{X[1,c]}|*3{X[1,c]}||X[1,c]}
\tabucline[1.5pt]{-}
& \mc{} & \multicolumn{4}{c}{cut-off} \\
\tabucline {3-6}
\mrc{1}{Various stuff\\(MeV)}
& \# of data
& \mc{A} & B & C & \mrc{1}{Ref. [bleh] \\ at B } \\
\tabucline[1pt] {-}
$np$ &&&&& \\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\tabucline {-}
$pp$ &&&&& \\
0 - 100 & number & value & value & value & value \\
0 - 190 & number & value & value & value & value \\
\tabucline[1.5pt]{-}
\end{tabu}
\end{table}
\end{document}