使用哪个命令来添加行分隔线,如最底部的图像(示例)所示?我使用的是 \hline ,但如果有多行,它会剪切列名。我已添加我的代码进度。谢谢
\begin{center}
\begin{adjustbox}{width=1 \textwidth}
\begin{tabular}{ *{16}{c | } }
\multirow{2}{*} {Instance} & \multicolumn{5}{c|}{\multirow{2}{*} {Single Level Linear Formulation} }
& \multicolumn{8}{c }{Scatter Search} \\
\hline
& & & & & & \multicolumn{3}{|c|}{Best} & \multicolumn{5}{c|}{Average} \\
& LeaderObj LB & LeaderObj UB & Follower Obj & \%GAP & CPU(s)
& Best OFL & \%GAP LB & \%GAP UB & Average OFL & Average OFF & \%GAP UB & \%GAP LB & CPU(s)
\\
\hline
test 90k20ta1 & 1935 & 2094 & 1169 & 8.22 & time
\\
test 90k20ta2 & 1968 & 2091 & 1173.6 & 6.25 & time
\\
\end{tabular}
\end{adjustbox}
\end{center}
答案1
我建议您使用该rotating
包及其sidewaystable
环境以横向方式排版表格。其次,不要使用被称为adjustbox
环境的普罗克拉斯提斯之床;相反,使用tabularx
环境并允许自动换行,同时将列内容居中。第三,不要使用任何垂直规则,并用包的宏替换\hline
和以获得间距良好的水平线。相信我,垂直线不会被遗漏。第四点也是最后一点(但并非最不重要),使用包的列类型将选定列中的数字在其隐式或显式小数标记上对齐。\cline
booktabs
S
siunitx
在以下示例中,列类型(即软件包提供的列类型C
的居中版本)是 13 个数据列的默认类型。每当使用列类型(基于上一段中提到的列类型)时,请务必将相应的标题单元格“包装”在包装器中。请注意以下代码中的和作为此类“包装”的示例。X
tabularx
T
S
\mC
\mC{Follower Obj}
\mC{\%GAP}
\documentclass{article} % or some other suitable document class
\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters appropriately
\usepackage{rotating, % for 'sidewaystable' environment
booktabs, % for well-spaced horizontal rules
tabularx, % for 'tabularx' environment
ragged2e, % for '\Centering' macro
siunitx} % for 'S' columntype (and 'table-format' option)
\newcolumntype{C}{>{\Centering\hspace{0pt}}X}
\newcolumntype{T}[1]{S[table-format=#1]} % align on (explicit or implicit) decimal marker
\newcommand\mC[1]{\multicolumn{1}{@{}C@{}}{#1}} % handy shortcut macro
\hyphenation{leader-obj} % permit hyphenation between 'leader' and 'obj'
\begin{document}
\begin{sidewaystable}
\setlength\tabcolsep{2pt} % default value: 6pt
\caption{A table with 14 columns\strut} % choose real caption as needed
\begin{tabularx}{\textwidth}{ @{} % occupy full width (height) of text block
l % left alignment, no line breaking allowed
CC % use 'C' col. type for first two data columns
T{4.1} % 4 integer digits, 1 decimal digit
T{2.2} % 2 integer digits, 2 decimal digits
*{11}{C} % remaining columns (respecify as needed)
@{} }
\toprule
Instance & \multicolumn{5}{c}{Single Level Linear Formulation}
& \multicolumn{8}{c}{Scatter Search} \\
\cmidrule(lr){2-6} \cmidrule(l){7-14}
& & & & & & \multicolumn{3}{c}{Best} &
\multicolumn{5}{c}{Average} \\
\cmidrule(lr){7-9} \cmidrule(l){10-14}
& LeaderObj LB & LeaderObj UB & \mC{Follower Obj} & \mC{\%GAP} & CPU(s)
& Best OFL & \%GAP LB & \%GAP UB
& Average OFL & Average OFF & \%GAP UB & \%GAP LB & CPU(s) \\
\midrule
test 90k20ta1 & 1935 & 2094 & 1169 & 8.22 & time & \dots
\\
test 90k20ta2 & 1968 & 2091 & 1173.6 & 17.24 & time & \dots
\\
\dots
\\
\bottomrule
\end{tabularx}
\end{sidewaystable}
\end{document}