我想
获得标签为 1-10 的列的相同宽度(除第一列 ~ X 的名称外的所有列)
能够调整“Y 的名称”的位置(使其居中或位于左侧。目前,它影响第二列的宽度)
有小数对齐的数字
(将表格大小减少X百分比?查看其缩略图(由 %? 设置)
\documentclass{article}
\usepackage{booktabs} % this package promotes good tabular style
\usepackage{caption} % for customising caption style
\usepackage{siunitx} % for decimal alignment
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\begin{table}[!ht]
\setlength{\tabcolsep}{4pt} %length between columns; default = 6
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
\caption{Aaaaaaaaaaaaaaaaa}
\begin{tabular}{c*{10}{c}}
\toprule
& {Name of Y} \\
\cmidrule(lr){2-11}
{Name of X} & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 \\
\midrule
2000 & 123 & 45617 & 1415 & 1111 & 11111 & 55555 & 55555 & 66666 & 777.7 & 88888 \\
2000 & 123 & 45617 & 1415 & 11 & 11111 & 55555 & 55555 & 66666 & 7777.7 & 88888 \\
\bottomrule
\end{tabular}
\end{table}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\end{document}
答案1
可以使用 更改“Y 的名称”的位置\multicolumn
。对于对齐,您可以使用S
提供的列类型siunitx
(该包提供了许多额外的可能性)。要使列的宽度相等,可以使用包tabularx
;要使其与配合使用siunitx
,需要通过添加一些额外的工作。
\begingroup
\catcode`\_=11
\catcode`\:=11
\gdef\tabularxcolumn#1{%
>{\__siunitx_table_collect_begin:Nn S{} }%
p{#1}
<{\__siunitx_table_print:}%
}
\endgroup
这只不过是对马丁·沙雷尔的回答如何将 siunitx 和 tabularx 一起使用?。但是,在您的情况下,表格似乎真的很宽,因此您可以使用包sidewaystable
中的功能额外旋转它rotating
(您强制读者改变阅读方向,但表格值更加清晰)。
完整示例:
\documentclass{article}
\usepackage{booktabs} % this package promotes good tabular style
\usepackage{caption} % for customising caption style
\usepackage{siunitx} % for decimal alignment
\usepackage{tabularx} % for columns of equal width
\usepackage{rotating} % for rotating objects
% make tabularx and siunitx cooperate
\begingroup
\catcode`\_=11
\catcode`\:=11
\gdef\tabularxcolumn#1{%
>{\__siunitx_table_collect_begin:Nn S{} }%
p{#1}
<{\__siunitx_table_print:}%
}
\endgroup
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\begin{sidewaystable}
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
\caption{Aaaaaaaaaaaaaaaaa}
\begin{tabularx}{\linewidth}{c*{10}{X}}
\toprule
& \multicolumn{10}{c}{Name of Y} \\
\cmidrule(lr){2-11}
{Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\
\midrule
2000 & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 8888.8 \\
2000 & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
\bottomrule
\end{tabularx}
\end{sidewaystable}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\end{document}
可以使用其他一些选项来\resizebox
缩放表格:
\resizebox{<width>}{<height>}{<content>}
修饰符!
不会改变自然尺寸。(如果表格太宽,纵向显示可能比缩放更好):
\documentclass{article}
\usepackage{booktabs} % this package promotes good tabular style
\usepackage{caption} % for customising caption style
\usepackage{siunitx} % for decimal alignment
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\begin{table}[!ht]
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
\caption{Aaaaaaaaaaaaaaaaa}
\resizebox{\textwidth}{!}{\begin{tabular}{c*{10}{S}}
\toprule
& \multicolumn{10}{c}{Name of Y} \\
\cmidrule(lr){2-11}
{Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\
\midrule
2000 & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 88.888 \\
2000 & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
\bottomrule
\end{tabular}}
\end{table}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\end{document}
还有\scalebox{<x-factor>}[<y-factor>]{contents}
,但使用它您需要通过反复试验来确定适当的因素。
\tabcolsep
减少并继续使用的另一种选择\resizebox
:
\documentclass{article}
\usepackage{booktabs} % this package promotes good tabular style
\usepackage{caption} % for customising caption style
\usepackage{siunitx} % for decimal alignment
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\begin{table}[!ht]
\setlength{\tabcolsep}{3pt} %length between columns; default = 6
\footnotesize
\centering
\captionsetup{singlelinecheck = on, justification = centering, labelfont = bf}
\caption{Aaaaaaaaaaaaaaaaa}
\resizebox{\textwidth}{!}{\begin{tabular}{c*{10}{S}}
\toprule
& \multicolumn{10}{c}{Name of Y} \\
\cmidrule(lr){2-11}
{Name of X} & {1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} & {9} & {10} \\
\midrule
2000 & 1.23 & 45.617 & 14.15 & 11.11 & 11.111 & 555.55 & 555.55 & 66.666 & 777.7 & 88.888 \\
2000 & 12.3 & 456.17 & 1.415 & 11 & 111.11 & 55.555 & 5555.5 & 66.666 & 7777.7 & 888.88 \\
\bottomrule
\end{tabular}}
\end{table}
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore.
\end{document}