![如何将内容添加到第二行?我试过 \thread,但不起作用](https://linux22.com/image/404337/%E5%A6%82%E4%BD%95%E5%B0%86%E5%86%85%E5%AE%B9%E6%B7%BB%E5%8A%A0%E5%88%B0%E7%AC%AC%E4%BA%8C%E8%A1%8C%EF%BC%9F%E6%88%91%E8%AF%95%E8%BF%87%20%5Cthread%EF%BC%8C%E4%BD%86%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
我在制作表格时遇到了很多麻烦。
我知道\thread
如何将单元格中的内容拆分成两行。但没有成功。
基本上,我想绘制如下的表格:
我的输出:
我在用
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xllrr}
我的完整 MWE:
\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{hhline, boldline}
\usepackage{seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e} % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{siunitx} %for table spacing to second row
\usepackage{threeparttable} %to add footnote below table
\usepackage{tabulary}
\usepackage{graphicx}
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xllrr}
% \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xrrrrrr}
\toprule
& & & \multicolumn{2}{c}{\textbf{Cholestrrol Levellll}} \\
\cmidrule{4-5}
& & & \thead{{\textbf{Equal}} \\ \textbf{variances} \\ \textbf{assumed}}
& \thead{{\textbf{Equal}} \\ \textbf{variances not} \\ \textbf{assumed}}\\
\midrule
\multicolumn{1}{l}{Levene's Test for Equality of Variances} & F
& & 0.314 & \\
& Sig. & & 0.579 & \\
\midrule
\multicolumn{1}{l}{t-test for Equality of Means} & t
& & 2.428 & 2.428 \\
& df & & 38 & 34.886 \\
& Sig. (2-tailed) & & 0.579 & 0.64273\\
& 95\% Confidence & Lower & 0.579 & 0.64273\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
答案1
最左边的列是“特殊”的,它是类型X
,这意味着它会调整大小以使标题达到您想要的宽度。现在,当您使用
\multicolumn{1}{l}{Levene's Test for Equality of Variances}
并且第二个这样的语句,你就会删除那个可怜的X
列。这让大卫·卡莱尔不高兴,桌子变得疯狂。如果你删除\multicolumn
第一列中的这些 s,你会得到
\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage{booktabs, ragged2e} % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\begin{document}
\begin{table}[h!]
\centering
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xllrr}
% \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xrrrrrr}
\toprule
& & & \multicolumn{2}{c}{\textbf{Cholestrrol Levellll}} \\
\cmidrule{4-5}
& & & \thead{{\textbf{Equal}} \\ \textbf{variances} \\ \textbf{assumed}}
& \thead{{\textbf{Equal}} \\ \textbf{variances not} \\ \textbf{assumed}}\\
\midrule
Levene's Test for Equality of Variances
& F
& & 0.314 & \\
& Sig. & & 0.579 & \\
\midrule
t-test for Equality of Means
& t
& & 2.428 & 2.428 \\
& df & & 38 & 34.886 \\
& Sig. (2-tailed) & & 0.579 & 0.64273\\
& 95\% Confidence & Lower & 0.579 & 0.64273\\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
一般而言,只有当与标题中指定的类型不同时, a\multicolumn{1}{<type>}{...}
才有意义。但是,在您的示例中,该列的唯一条目是条目。type
X
\multicolumn