我想将数字按小数点对齐。我在表格中使用了以下代码:
\usepackage{siunitx}
\usepackage{dcolumn}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{cc|cccc}
\toprule
\multicolumn{2}{c}{\multirow{2}[2]{*}{Variable}} & \multirow{2}[2]{*}{Mean } & \multicolumn{1}{r}{\multirow{2}[2]{*}{Standard Deviation}} & \multirow{2}[2]{*}{Skewness} & \multirow{2}[2]{*}{Kurtosis} \\
\multicolumn{2}{c}{} & & & & \\
\midrule
\multicolumn{2}{c|}{} & & & & \\
\multicolumn{2}{c|}{a} & 6.23 & 1.89 & 0.65 & 2.00 \\
\multicolumn{2}{c|}{b} & 25.74 & 14.84 & 0.85 & 2.73 \\
\multicolumn{2}{c|}{c} & 30.94 & 17.05 & 0.00 & 1.96 \\
\multicolumn{2}{c|}{d} & 42.88 & 15.40 & 0.78 & 3.15 \\
\multicolumn{2}{c|}{e} & 30.14 & 14.39 & 1.39 & 4.28 \\
\multicolumn{2}{c|}{f} & 23.03 & 14.26 & 1.84 & 6.13 \\
\multicolumn{2}{c|}{g} & 51.67 & 17.66 & -0.29 & 2.30 \\
\multicolumn{2}{c|}{h} & 41.48 & 19.96 & 0.70 & 2.66 \\
\multicolumn{2}{c|}{i} & 52.89 & 23.54 & -0.36 & 2.33 \\
\multicolumn{2}{c|}{j} & 40.23 & 20.99 & 0.01 & 2.03 \\
\multicolumn{2}{c|}{k} & 46.38 & 16.54 & 1.03 & 3.02 \\
\multicolumn{2}{c|}{l} & 100.09 & 1.05 & -1.35 & 6.44 \\
\multicolumn{2}{c|}{m} & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
非常感谢!
答案1
您的代码中存在多个冗余。前面的两列|
未使用;而且\multirow
似乎完全没有必要。空行不是添加垂直间距的最佳方式(顺便说一句,这似乎不太好)。
使用S
from siunitx
,指定列格式。
\documentclass{article}
\usepackage{siunitx,booktabs}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Add caption}\label{tab:addlabel}
\begin{tabular}{
l
S[table-format=3.2]
S[table-format=2.2]
S[table-format=-1.2]
S[table-format=1.2]
}
\toprule
Variable & {Mean} & {Standard Deviation} & {Skewness} & {Kurtosis} \\
\midrule
a & 6.23 & 1.89 & 0.65 & 2.00 \\
b & 25.74 & 14.84 & 0.85 & 2.73 \\
c & 30.94 & 17.05 & 0.00 & 1.96 \\
d & 42.88 & 15.40 & 0.78 & 3.15 \\
e & 30.14 & 14.39 & 1.39 & 4.28 \\
f & 23.03 & 14.26 & 1.84 & 6.13 \\
g & 51.67 & 17.66 & -0.29 & 2.30 \\
h & 41.48 & 19.96 & 0.70 & 2.66 \\
i & 52.89 & 23.54 & -0.36 & 2.33 \\
j & 40.23 & 20.99 & 0.01 & 2.03 \\
k & 46.38 & 16.54 & 1.03 & 3.02 \\
l & 100.09 & 1.05 & -1.35 & 6.44 \\
m & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
我建议使用这个变体,基于siunitx
。我加载了caption
标题和表格之间的正确间距。通常,由于水平规则周围的填充,booktabs 中的规则不应与垂直规则一起使用。但是,单个较粗的垂直灰色规则是可以接受的(在我看来)。我没有使用multirow, replacing it with
\setcellgapes from
makecell`。
\documentclass{report}
\usepackage{siunitx}
\usepackage[svgnames]{xcolor}
\usepackage{caption, booktabs, multirow, makecell}
\begin{document}
\begin{table}[!htb]%
\sisetup{table-format=2.2, table-number-alignment=center}
\setcellgapes{3pt}\makegapedcells
\centering
\caption{Add caption}
\begin{tabular}{c!{\color{LightGrey!80}\vline width 2.5pt}S[table-format=3.2]S S[table-format=-1.2]S}
\toprule
\multicolumn{1}{c}{Variable} & {Mean} & {\makecell{Standard\\ Deviation}} & {Skewness} & {Kurtosis} \\
\midrule
a & 6.23 & 1.89 & 0.65 & 2.00 \\
b & 25.74 & 14.84 & 0.85 & 2.73 \\
c & 30.94 & 17.05 & 0.00 & 1.96 \\
d & 42.88 & 15.40 & 0.78 & 3.15 \\
e & 30.14 & 14.39 & 1.39 & 4.28 \\
f & 23.03 & 14.26 & 1.84 & 6.13 \\
g & 51.67 & 17.66 & -0.29 & 2.30 \\
h & 41.48 & 19.96 & 0.70 & 2.66 \\
i & 52.89 & 23.54 & -0.36 & 2.33 \\
j & 40.23 & 20.99 & 0.01 & 2.03 \\
k & 46.38 & 16.54 & 1.03 & 3.02 \\
l & 100.09 & 1.05 & -1.35 & 6.44 \\
m & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}%
\end{table}%
\end{document}
答案3
不确定这个表格的用途是什么\multirow
!希望下面修改后的标签能适合你:
\documentclass{book}
\usepackage{siunitx}
\usepackage{multirow,dcolumn,booktabs}
\begin{document}
\newcolumntype{d}[1]{D{.}{.}{#1}}%
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{cc|d{3,2}d{2,2}d{2,2}d{1,2}}
\toprule
Variable & &\multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Standard Deviation} & \multicolumn{1}{c}{Skewness} & \multicolumn{1}{c}{Kurtosis} \\
\midrule
\multicolumn{2}{c|}{} & & & & \\
\multicolumn{2}{c|}{a} & 6.23 & 1.89 & 0.65 & 2.00 \\
\multicolumn{2}{c|}{b} & 25.74 & 14.84 & 0.85 & 2.73 \\
\multicolumn{2}{c|}{c} & 30.94 & 17.05 & 0.00 & 1.96 \\
\multicolumn{2}{c|}{d} & 42.88 & 15.40 & 0.78 & 3.15 \\
\multicolumn{2}{c|}{e} & 30.14 & 14.39 & 1.39 & 4.28 \\
\multicolumn{2}{c|}{f} & 23.03 & 14.26 & 1.84 & 6.13 \\
\multicolumn{2}{c|}{g} & 51.67 & 17.66 & -0.29 & 2.30 \\
\multicolumn{2}{c|}{h} & 41.48 & 19.96 & 0.70 & 2.66 \\
\multicolumn{2}{c|}{i} & 52.89 & 23.54 & -0.36 & 2.33 \\
\multicolumn{2}{c|}{j} & 40.23 & 20.99 & 0.01 & 2.03 \\
\multicolumn{2}{c|}{k} & 46.38 & 16.54 & 1.03 & 3.02 \\
\multicolumn{2}{c|}{l} & 100.09 & 1.05 & -1.35 & 6.44 \\
\multicolumn{2}{c|}{m} & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}
答案4
你的 MWE 不完整。我不得不添加booktabs
包和multirow
包。
这里,解决方案是使用S
列(来自siunitx
包)。
\documentclass{article}
\usepackage{siunitx}
\usepackage{dcolumn}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Add caption}
\begin{tabular}{cc|SSSS}
\toprule
\multicolumn{2}{c}{\multirow{2}[2]{*}{Variable}} & {\multirow{2}[2]{*}{Mean}} & {\multirow{2}[2]{*}{Standard Deviation}} & {\multirow{2}[2]{*}{Skewness}} & {\multirow{2}[2]{*}{Kurtosis}} \\
\multicolumn{2}{c}{} & & & & \\
\midrule
\multicolumn{2}{c|}{} & & & & \\
\multicolumn{2}{c|}{a} & 6.23 & 1.89 & 0.65 & 2.00 \\
\multicolumn{2}{c|}{b} & 25.74 & 14.84 & 0.85 & 2.73 \\
\multicolumn{2}{c|}{c} & 30.94 & 17.05 & 0.00 & 1.96 \\
\multicolumn{2}{c|}{d} & 42.88 & 15.40 & 0.78 & 3.15 \\
\multicolumn{2}{c|}{e} & 30.14 & 14.39 & 1.39 & 4.28 \\
\multicolumn{2}{c|}{f} & 23.03 & 14.26 & 1.84 & 6.13 \\
\multicolumn{2}{c|}{g} & 51.67 & 17.66 & -0.29 & 2.30 \\
\multicolumn{2}{c|}{h} & 41.48 & 19.96 & 0.70 & 2.66 \\
\multicolumn{2}{c|}{i} & 52.89 & 23.54 & -0.36 & 2.33 \\
\multicolumn{2}{c|}{j} & 40.23 & 20.99 & 0.01 & 2.03 \\
\multicolumn{2}{c|}{k} & 46.38 & 16.54 & 1.03 & 3.02 \\
\multicolumn{2}{c|}{l} & 100.09 & 1.05 & -1.35 & 6.44 \\
\multicolumn{2}{c|}{m} & 99.57 & 1.36 & -0.45 & 2.06 \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}