这是我使用的表的 MWE dcolumn
,其中我按小数对齐:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{dcolumn}
\usepackage{tabularx, multirow, booktabs}
\usepackage{amsmath}
\begin{document}
\begin{table}[t]
\centering \footnotesize
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla }
\begin{tabularx}{\linewidth}{l *{8}{D{.}{.}{-2}}}
\toprule
&\multicolumn{2}{c}{Column 1 is here}
&\multicolumn{2}{c}{Column 2 is here}
&\multicolumn{2}{c}{Column 3 is here}
&\multicolumn{2}{c}{Column 4 is here}\\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
&a &b
&a &b
&a &b
&a &b \\\midrule \\ [-2ex]
asd &0.01^{**} &0.01^{***} &0.100^{**} &0.100^{**} &0.100^{**} &0.100^{**} &0.100^{**} &0.10^{**}\\
\bottomrule
\end{tabularx}
\caption*{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla }
\end{table}
\end{document}
原则上这是可行的,但是表格的水平长度有问题:
有没有办法让表格在水平方向上更紧凑一些?目前,各列之间的间距相当大。
编辑(3/12)添加标题:是否可以在表格中添加“标题”,类似于以下内容:
\documentclass{article}
\usepackage{dcolumn}
\usepackage{tabularx, multirow, booktabs}
\usepackage[skip=1ex]{caption} % new
\usepackage{xparse} % not needed at recent LaTeX version
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[ht]
\centering
\footnotesize
\setlength\tabcolsep{0pt}
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}
*{3}{D{.}{.}{6}}}
\toprule
& \mcc[2]{Column 4 is here} \\
\cmidrule{2-3}
& \mcc{a} & \mcc{b} \\
\midrule
\multicolumn{3}{l}{Panel X: This is my title}\\
asd & 0.01^{**} & 0.01^{***} \\
\\
\multicolumn{3}{l}{Panel Y: This is my looooooong title}\\
asd & 0.01^{**} & 0.01^{***} \\
\bottomrule
\end{tabular*}
\caption*{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla }
\end{table}
\end{document}
我看到的唯一问题是它破坏了对齐。
答案1
像这样?
tabularx
我建议不要使用宏,而要使用宏进行计算tabular*
。您还需要更正列格式。\tabcolsep
@{\extracolsep{\fill}}
D
看起来,您使用第二个标题作为表格的注释。如果是这种情况,那么您caption
也需要加载所需的格式包:
\documentclass{article}
\usepackage{dcolumn}
\usepackage{tabularx, multirow, booktabs}
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{table}[ht]
\centering
\footnotesize
\setlength\tabcolsep{0pt}
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}
*{8}{D{.}{.}{6}}}
\toprule
&\multicolumn{2}{c}{Column 1 is here}
&\multicolumn{2}{c}{Column 2 is here}
&\multicolumn{2}{c}{Column 3 is here}
&\multicolumn{2}{c}{Column 4 is here}\\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
&a &b
&a &b
&a &b
&a &b \\ \midrule
asd &0.01^{**} &0.01^{***} &0.100^{**} &0.100^{**} &0.100^{**} &0.100^{**} &0.100^{**} &0.10^{**}\\
\bottomrule
\end{tabular*}
\caption*{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla }
\end{table}
\end{document}
编辑:或者您可能更喜欢水平居中的列标题:
\documentclass{article}
\usepackage{dcolumn}
\usepackage{tabularx, multirow, booktabs}
\usepackage[skip=1ex]{caption} % new
%\usepackage{xparse} % not needed at recent LaTeX version
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[ht]
\centering
\footnotesize
\setlength\tabcolsep{0pt}
\caption{bla bla bla bla bla bla bla bla bla bla bla bla bla bla}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}
*{8}{D{.}{.}{6}}}
\toprule
& \mcc[2]{Column 1 is here}
& \mcc[2]{Column 2 is here}
& \mcc[2]{Column 3 is here}
& \mcc[2]{Column 4 is here} \\
\cmidrule{2-3} \cmidrule{4-5} \cmidrule{6-7} \cmidrule{8-9}
& \mcc{a} & \mcc{b} & \mcc{a} & \mcc{b}
& \mcc{a} & \mcc{b} & \mcc{a} & \mcc{b} \\
\midrule
asd & 0.01^{**} & 0.01^{***} & 0.100^{**} & 0.100^{**}
& 0.100^{**} & 0.100^{**} & 0.100^{**} & 0.10^{**} \\
\bottomrule
\end{tabular*}
\caption*{bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla }
\end{table}
\end{document}