下面的代码生成下表:
\documentclass[a4paper]{article}
\begin{document}
\begin{center}
\begin{table}
\setcellgapes{3pt}\makegapedcells
\begin{tabularx}{1.175\linewidth}{c|*{5}{>{\centering\arraybackslash}X}>{\centering\arraybackslash}X}\toprule
\multicolumn{6}{c} {\makecell{\textit{Number of dendrograms in each group for 10,000 bootstrap samples }}} \\
\hline
& \multicolumn{1}{c} {\makecell{G1}}
& \multicolumn{1}{c} {\makecell{G2}}
& \multicolumn{1}{c} {\makecell{G3}}
& \multicolumn{1}{c} {\makecell{G4}}
& \multicolumn{1}{c} {\makecell{G5}} \\
\midrule
\hline
\# of Subgroups & 0 & 0 & 2 & 0 & 5\\
\# of Dendrograms & 63 & 15 & 6 & 5 & 1\\
\hline
\end{tabularx}
\caption{}
\label{table:prosConsOptionalApproaches}
\end{table}
\end{center}
\end{document}
我该如何在“树状图数量....”旁边添加此表的标题。即在顶部单元格内
答案1
- 不清楚为什么你定义了 11 列,但只使用了 6 列
- 你的表中的使用
makecell
是多余的 - 使用
\multicolumn{1}{c}{....}
只会导致问题(如果列标题比列宽宽)。它们是多余的 - 我不会将标题放在单元格内,而只会
\toprule
在它上面添加并使用标准格式的标题 部分考虑到伯纳德答案,你的代码可以简化为:
\documentclass[a4paper]{article} \usepackage[showframe]{geometry} \usepackage{booktabs, ltablex, makecell} \usepackage{caption} \begin{document} \keepXColumns \setcellgapes{3pt}\makegapedcells \begin{tabularx}{\linewidth}{c|*{5}{>{\centering\arraybackslash}X}}%1.175 \toprule \addlinespace \captionsetup{textfont=it, skip=0.25ex} \caption{Number of dendrograms in each group for 10,000 bootstrap samples} \label{table:prosConsOptionalApproaches}\\ \midrule & G1 & G2 & G3 & G4 & G5 \\ \midrule \midrule \# of Subgroups & 0 & 0 & 2 & 0 & 5 \\ \# of Dendrograms & 63 & 15 & 6 & 5 & 1 \\ \bottomrule \end{tabularx} \end{document}
答案2
由于 longtable 的工作方式,您可以加载ltablex
包,它将 的功能带给longtable
。tabularx
代码如下:
\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage{ltablex, makecell, booktabs, caption}
\begin{document}
\keepXColumns
\setcellgapes{3pt}\makegapedcells
\begin{tabularx}{\linewidth}{c|*{5}{>{\centering\arraybackslash}X}>{\centering\arraybackslash}X}%1.175
\toprule
\multicolumn{6}{c} {\makecell{\textit{Number of dendrograms in each group for 10,000 bootstrap samples }}} \\[1ex]
\captionsetup{labelsep=none}
\caption{}
\label{table:prosConsOptionalApproaches}\\
\midrule
\endfirsthead
& \multicolumn{1}{c} {\makecell{G1}}
& \multicolumn{1}{c} {\makecell{G2}}
& \multicolumn{1}{c} {\makecell{G3}}
& \multicolumn{1}{c} {\makecell{G4}}
& \multicolumn{1}{c} {\makecell{G5}} \\
\midrule
\midrule
\# of Subgroups & 0 & 0 & 2 & 0 & 5\\
\# of Dendrograms & 63 & 15 & 6 & 5 & 1\\
\bottomrule
\end{tabularx}
\end{document}
笔记:我将尺寸缩小到tabularx
到\linewidth
,因为这是一个不同的问题。如果您想要一个居中的 tabularx,宽度大于\textwidth
,嵌套在adjustwidth
环境中,从changepage
答案3
用一个\parbox
:
\documentclass[a4paper]{article}
\usepackage{tabularx,booktabs,caption}
\begin{document}
\begin{table}
\centering
\captionsetup{skip=0pt}
\begin{tabularx}{\columnwidth}{
c
*{5}{>{\centering\arraybackslash}X}
}
\toprule
\multicolumn{6}{@{}p{\textwidth}@{}}{%
\parbox{\textwidth}{
\caption{Number of dendrograms in each
group for 10,000 bootstrap samples}%
\label{table:prosConsOptionalApproaches}%
}} \\
\midrule
& G1 & G2 & G3 & G4 & G5 \\
\midrule
\# of Subgroups & 0 & 0 & 2 & 0 & 5\\
\# of Dendrograms & 63 & 15 & 6 & 5 & 1\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
我已经删除了makecell
除垂直和双重规则之外的所有设置。