我需要这张表的帮助。值对齐到小数点后 5 位,我必须使用dcolumn
。这就是我想要的:
这就是我所拥有的:
\documentclass[10pt,a4paper,twoside]{article}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}[h!]
\begin{center}
\caption{Experimentální výsledky}
\label{tab:table1}
\begin{tabular}{ l c c r r r }
\toprule
& $\alpha$ & $\beta$ & $\gamma$ & $\delta$ & $\chi$ \\ \hline
Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\ \hline
\multirow{4}{*}{Pokus 2} & 84,99683 & -88,7 & 33,551 & 83,436 & -59,9\\
& -67 & -81,46 & -98 & 54,0456 & -28\\
& -23,8 & -63 & -9,47 & 58,03674 & -89,1\\
& -61,4 & -68,19 & -13,2 & -80,2 & -47,3\\ \hline
Pokus 6 & -87,94 & -52 & 68,548 & 17,0284 & -49,1 \\ \hline
Pokus 7 & -72,55 & -66,06 & -50 & -66,3 & 92,27074\\ \hline
Pokus 8 & 12,475 & 73,464 & 23,9323 & 52,959 & -87,71\\ \hline
Pokus 9 & 99,24615 & -27,17 & 49,5099 & 88,7448 & 87,22619\\ \hline
Pokus 10 & 99,268 & 83,8816 & -94,4 & -25,5 & 47,873\\
\bottomrule
\end{tabular}
\end{center}
\end{table}
\end{document}
答案1
我针对您的 MWE 所做的更改如下:
- 您可以
\centering
在\begin{center} ... \end{center}
表环境中使用 - 您需要在命令中嵌入第一行(标题)的内容
\multicolumn{1}{c}{}
来覆盖D
列类型 - 该语法
*{n}{t}
允许您定义n
类型列t
- 我添加了
\otoprule
分隔符,这样就可以使用相同的线条粗细,\toprule
但标题行之间的间距相等 - 可以使用 来实现列之间的额外间距(出现在您的参考图像中)
\setlength{\tabcolsep}{10pt}
。您可以输入您喜欢的长度,而不是10pt
。如果您想保留默认的列间距,只需注释掉该行即可。 - 即使在您的参考图像中标题位于表格的底部,最好也将其保持在顶部,就像您已经做的那样。
所以你有了:
\documentclass[10pt,a4paper,twoside]{article}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multirow}
\newcommand{\otoprule}{\midrule[\heavyrulewidth]} % vertically centered with respect to the row above and below, but same thickness as \{top,bottom}rule
\begin{document}
\begin{table}[h!]
\centering
\caption{Experimentální výsledky}
\label{tab:table1}
\setlength{\tabcolsep}{10pt}
\begin{tabular}{l *{5}{D{,}{,}{3.5}}}
\toprule
& \multicolumn{1}{c}{$\alpha$} & \multicolumn{1}{c}{$\beta$} & \multicolumn{1}{c}{$\gamma$} & \multicolumn{1}{c}{$\delta$} & \multicolumn{1}{c}{$\chi$} \\ \otoprule
Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\ \midrule
\multirow{4}{*}{Pokus 2} & 84,99683 & -88,7 & 33,551 & 83,436 & -59,9 \\
& -67 & -81,46 & -98 & 54,0456 & -28 \\
& -23,8 & -63 & -9,47 & 58,03674 & -89,1 \\
& -61,4 & -68,19 & -13,2 & -80,2 & -47,3 \\ \midrule
Pokus 6 & -87,94 & -52 & 68,548 & 17,0284 & -49,1 \\ \midrule
Pokus 7 & -72,55 & -66,06 & -50 & -66,3 & 92,27074 \\ \midrule
Pokus 8 & 12,475 & 73,464 & 23,9323 & 52,959 & -87,71 \\ \midrule
Pokus 9 & 99,24615 & -27,17 & 49,5099 & 88,7448 & 87,22619 \\ \midrule
Pokus 10 & 99,268 & 83,8816 & -94,4 & -25,5 & 47,873 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
使用siunitx
正确定义的数字格式,MWE 为:
\documentclass[10pt,a4paper,twoside]{article}
\usepackage{booktabs, multirow}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[h!]
\centering
\sisetup{output-decimal-marker={,}}
\caption{Experimentální výsledky}
\label{tab:table1}
\begin{tabular}{ l S[table-format=-2.5]
*{2}{S[table-format=-2.4]}
*{2}{S[table-format=-2.5]}
}
\toprule
& {$\alpha$} & {$\beta$} & {$\gamma$} & {$\delta$} & {$\chi$} \\
\midrule
Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\
\midrule
Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\ \hline
\multirow{4}{*}{Pokus 2}
& 84,99683 & -88,7 & 33,551 & 83,436 & -59,9 \\
& -67 & -81,46 & -98 & 54,0456 & -28 \\
& -23,8 & -63 & -9,47 & 58,03674 & -89,1 \\
& -61,4 & -68,19 & -13,2 & -80,2 & -47,3 \\
\midrule
Pokus 6 & -87,94 & -52 & 68,548 & 17,0284 & -49,1 \\
Pokus 7 & -72,55 & -66,06 & -50 & -66,3 & 92,27074 \\
Pokus 8 & 12,475 & 73,464 & 23,9323 & 52,959 & -87,71 \\
Pokus 9 & 99,24615 & -27,17 & 49,5099 & 88,7448 & 87,22619 \\
Pokus 10 & 99,268 & 83,8816 & -94,4 & -25,5 & 47,873 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
(红线表示文本边框)
siunitx
启用对所有数字的简单四舍五入,例如四舍五入为小数点后三位:
\documentclass[a4paper,twoside]{article}
\usepackage{booktabs, multirow}
\usepackage{siunitx}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{table}[h!]
\centering
\sisetup{output-decimal-marker={,},
round-mode=places,
round-precision=3,
round-integer-to-decimal,
table-format=-2.3
}
\caption{Experimentální výsledky}
\label{tab:table1}
\begin{tabular}{ l *{5}{S} }
\toprule
& {$\alpha$} & {$\beta$} & {$\gamma$} & {$\delta$} & {$\chi$} \\
\midrule
Pokus 1 & 9,03983 & 20,7265 & 70,905 & -31,83 & -75,2 \\
\midrule
\multirow{4}{*}{Pokus 2}
& 84,99683 & -88,7 & 33,551 & 83,436 & -59,9 \\
& -67 & -81,46 & -98 & 54,0456 & -28 \\
& -23,8 & -63 & -9,47 & 58,03674 & -89,1 \\
& -61,4 & -68,19 & -13,2 & -80,2 & -47,3 \\
\midrule
Pokus 6 & -87,94 & -52 & 68,548 & 17,0284 & -49,1 \\
Pokus 7 & -72,55 & -66,06 & -50 & -66,3 & 92,27074 \\
Pokus 8 & 12,475 & 73,464 & 23,9323 & 52,959 & -87,71 \\
Pokus 9 & 99,24615 & -27,17 & 49,5099 & 88,7448 & 87,22619 \\
Pokus 10 & 99,268 & 83,8816 & -94,4 & -25,5 & 47,873 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}