我的代码如下:
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\begin{table}[h]
\centering
\begin{tabular}{>{\centering\arraybackslash}m{1in}|l|l|}
\cline{2-3}
& \textbf{Hypothesis Testing} & \textbf{Comparison between} \\ \hline
\multicolumn{1}{|l|}{\multirow{4}{*}{\textbf{Mean Comparison}}} & One Sample t-test & a sample mean and known reference mean \\ \cline{2-3}
\multicolumn{1}{|l|}{} & Two Sample t-test & means of two groups \\ \cline{2-3}
\multicolumn{1}{|l|}{} & Paired t-test & means of two groups for paired data \\ \cline{2-3}
\multicolumn{1}{|l|}{} & ANOVA (F-test) & means of more than two groups \\ \hline
\multicolumn{1}{|l|}{\textbf{Variance Comparison}} & Variance test & variances of at least two groups \\ \hline
\multicolumn{1}{|l|}{\textbf{Proportion Comparison}} & Chi\textsuperscript{2} test & proportions of at least two groups \\ \hline
\end{tabular}
\end{table}
输出如下:
但期望的输出应该是:
我已经尝试过这里的解决方案:
但目前还没有任何效果。有人能帮我吗?
答案1
要在里面换行,\multirow
你必须使用长度,而不是*
像
\multirow{4}{1in}{\centering\textbf{Mean Comparison}}
带有\centering
。此外,由于您使用的是>{\centering\arraybackslash}m{1in}
第一列,因此所有\multicolumn{1}{|l|}{}
s 都是多余的。删除它们将允许换行并使内容根据需要居中。
\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{graphicx}
\begin{document}
\begin{table}[h]
\centering
\begin{tabular}{|>{\centering\arraybackslash}m{1in}|l|l|}
\cline{2-3}
\multicolumn{1}{c|}{} & \textbf{Hypothesis Testing} & \textbf{Comparison between} \\ \hline
\multirow{4}{1in}{\centering\textbf{Mean Comparison}} & One Sample t-test & a sample mean and known reference mean \\ \cline{2-3}
& Two Sample t-test & means of two groups \\ \cline{2-3}
& Paired t-test & means of two groups for paired data \\ \cline{2-3}
& ANOVA (F-test) & means of more than two groups \\ \hline
\textbf{Variance Comparison} & Variance test & variances of at least two groups \\ \hline
\textbf{Proportion Comparison} & Chi\textsuperscript{2} test & proportions of at least two groups \\ \hline
\end{tabular}
\end{table}
\end{document}
但是,您的表格太宽,无法容纳在文本宽度内。您可以考虑使用p
或m
键入列作为最后一列。我没有添加它,因为想法是重现图片中的表格。