我想使其成为内容中心,但我不知道还能改变什么。
\documentclass[12pt,oneside]{book}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{makecell,siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htp!]
\centering
\begin{tabular}{
l
S[table-format=2.2,table-space-text-post=\%]
S[table-format=3.2,,table-space-text-post=\%]
}
\toprule
& \multicolumn{2}{c}{\thead{\makebox[0pt]{\textbf{Descriptive Analysis 1}}}}\\
\cmidrule{2-3}
& \textbf{MM}
& \textbf{CM} \\
\midrule
N & {10} & {10} \\
Mean & 91.45\% & 8.55\% \\
Median & 94.74\% & 5.26\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
您应该固定列的位数,并且需要在两个 周围加上S
两对。您也可以考虑删除 周围的括号,但我会让您自己决定。{}
textbf{...}
{10}
\documentclass{article}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{makecell,siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}[htp!]
\setlength{\tabcolsep}{1em}
\centering
\begin{tabular}{
l
S[table-format=2.2,table-space-text-post=\%]
S[table-format=2.2,table-space-text-post=\%]
}
\toprule
& \multicolumn{2}{c}{\thead{\makebox[0pt]{\textbf{Descriptive Analysis 1}}}}\\
\cmidrule{2-3}
& {\textbf{MM}}
& {\textbf{CM}} \\
\midrule
N & {10} & {10} \\
Mean & 91.45\% & 8.55\% \\
Median & 94.74\% & 5.26\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
您需要在所有没有百分比的地方将S
列覆盖为(第一列中的数字应该是 4.2):c
\begin{tabular}{
l
S[table-format=4.2,table-space-text-post=\%]
S[table-format=3.2,,table-space-text-post=\%]
}
\toprule
& \multicolumn{2}{c}{\thead{\makebox[0pt]{\textbf{Descriptive Analysis 1}}}}\\
\cmidrule{2-3}
& \multicolumn{1}{c}{\textbf{MM}} & \multicolumn{1}{c}{\textbf{CM}} \\
\midrule
N & \multicolumn{1}{c}{10} & \multicolumn{1}{c}{10} \\
Mean & 91.45\% & 8.55\% \\
Median & 94.74\% & 5.26\% \\
\bottomrule
\end{tabular}
答案3
以下是我对您的表格的解释。由于您已将表格按小数点对齐,因此没有小数的数字被设置在左侧。您可以通过将两个数字括10
在花括号 ( {10}
) 中或使用 来解决这个问题\multicolumn{1}{c}{10}
,但这在印刷上可能不正确。
\documentclass[12pt,oneside]{book}
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
\usepackage{makecell,siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{}
l
S[table-format=2.2,table-space-text-post=\%]
S[table-format=2.2,table-space-text-post=\%] % As @Zarko says, reduce this numer to 1.1 if number 10 is centred, else 2.2
@{}}
\toprule
& \multicolumn{2}{@{}c@{}}{\thead{\textbf{Descriptive Analysis 1}}}\\
\cmidrule{2-3}
& \multicolumn{1}{c}{\textbf{MM}}
& \multicolumn{1}{c}{\textbf{CM}} \\
\midrule
%N & {10} & {10} \\ % Enclose in brackets to centre the content
N & 10 & 10 \\
Mean & 91.45\% & 8.55\% \\
Median & 94.74\% & 5.26\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案4
还有一个变化……
您的问题是由于multicolumn
单元格中的文本比跨列的自然宽度要宽。如果您使这些列的宽度相等,例如确定它们的宽度足够大,问题就解决了,就像以下 MWE 中所做的那样:
\documentclass[12pt,oneside]{book}
\usepackage{booktabs, makecell}
\renewcommand\theadfont{\small\bfseries}
\renewcommand\theadgape{}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\sisetup{table-format=2.2,
table-space-text-post={\%},
table-column-width=5em} % <-----
\begin{tabular}{@{} l S S @{}}
\toprule
& \multicolumn{2}{@{}c@{}}{\thead{Descriptive Analysis 1}} \\
\cmidrule{2-3}
& {\thead{MM}} & {\thead{CM}} \\
\midrule
N & {10} & {10} \\
Mean & 91.45\% & 8.55\% \\
Median & 94.74\% & 5.26\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}