以下代码为第二行和第三行的单元格生成不同的垂直对齐方式(顶部对齐与居中)。顶部对齐是所需的结果。为什么会发生这种情况?我该如何修复?
\documentclass[11pt, letterpaper]{article}
\begin{document}
\begin{tabular}{|l|l|l|l|}
\hline
1 & 2 & 3 & 4 \\ \hline
\textbf{Field 1} & \multicolumn{3}{p{10cm}|}{The label for Field 1 is aligned to the top of its cell, even though it is more than one line high due to this cell extending to multiple lines.} \\ \hline
\textbf{Field 2} & Data for field 2 & \textbf{Field 3} & \begin{tabular}{@{}l@{}} List of \\ Items for \\ Third field \end{tabular} \\ \hline
\end{tabular}
\end{document}
答案1
这个怎么样?
\documentclass{article}
\begin{document}
\begin{tabular}{|l|l|l|l|}
\hline
1 & 2 & 3 & 4\\
\hline
\textbf{Field 1}&
\multicolumn{3}{p{10cm}|}{The label for Field 1 is aligned to the
top of its cell, even though it is more than one line high due
to this cell extending to multiple lines.}\\
\hline
\textbf{Field 2}&Data for field 2&\textbf{Field 3}&
\begin{tabular}[t]{@{}l@{}} List of\\
Items for\\
Third field
\end{tabular}
\\
\hline
\end{tabular}
\end{document}
答案2
这是你想要的吗?我用包简化了你的代码makecell
,并m
在以下位置使用了列类型p
:
\documentclass[11pt, letterpaper]{article}
\usepackage{array}
\usepackage{makecell}
\begin{document}
\setlength{\extrarowheight}{3pt}
\begin{tabular}{|l|l|l|l|}
\hline
1 & 2 & 3 & 4 \\ \hline
\textbf{Field 1} & \multicolumn{3}{m{10cm}|}{The label for Field 1 is aligned to the top of its cell, even though it is more than one line high due to this cell extending to multiple lines.} \\ \hline
\textbf{Field 2} & Data for field 2 & \textbf{Field 3} & \makecell[l]{List of \\ Items for \\ Third field } \\ \hline
\end{tabular}
\end{document}