使用多行实现垂直对齐和文本换行

使用多行实现垂直对齐和文本换行

我在多行表中垂直对齐(和换行)文本时遇到问题。因此,我希望 estmeed 社区能在这方面提供一些帮助。请参见下文:

\begin{table}
\caption{Story of Humpty Dumpty}
\centering
\begin{tabular}{c|c|c}
\hline
\multirow{3}{*}{Humpty Dumpty Sat} & on & \begin{tabular}[c]{@{}c@{}}the wall\\ and had a great fall  \end{tabular}\\ \cline{2-3} 
& \begin{tabular}[c]{@{}c@{}} on\end{tabular} & \begin{tabular}[c]{@{}c@{}}the wall\\ and had a great fall \end{tabular}\\ \cline{2-3} & \begin{tabular}[c]{@{}c@{}}on\\ \end{tabular} & \begin{tabular}[c]{@{}c@{}}the wall\\ and had a great fall\end{tabular} \\ \hline
\end{tabular}
\end{table}

我希望实现以下目标:

在此处输入图片描述

答案1

垂直对齐

在此处输入图片描述

 \multirow{5}{*}{Humpty Dumpty Sat} & on & \begin{tabular}[c]{@{}c@{}}the wall\\ and had a great fall  \end{tabular}\\ \cline{2-3} 

另外将文本换行

在此处输入图片描述

\multirow{5}{0.2\textwidth}{\centering Humpty Dumpty Sat} 

答案2

或者,使用较短的代码,采用m列类型并center设置“多行单元格:

\documentclass{article}
\usepackage{array, multirow}

\begin{document}
    \begin{table}
\caption{Story of Humpty Dumpty}
\centering
\renewcommand\multirowsetup{\centering} % <---
\renewcommand\arraystretch{1.3}
\begin{tabular}{p{6em}|c|>{\centering\arraybackslash}m{8em}} <---
    \hline
\multirow{4.5}{=}{Humpty Dumpty Sat} % 4.5=6 spanned lines-2 lines text + 0.5 line for gaps in rows
    & on    & the wall and had a great fall \\ \cline{2-3}
    & on    & the wall and had a great fall \\ \cline{2-3} 
    & on    & the wall and had a great fall \\ 
    \hline
\end{tabular}
    \end{table}
\end{document}

在此处输入图片描述

相关内容