\begin{table}[!h]
\centering
\caption{Titel}
\resizebox{.95\columnwidth}{!}{%
\begin{tabular}{p{4.5cm}p{10cm}p{3.5cm}}
\hline
Name & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
{long_title which goes over two coloums}\\
\hline
Explanation & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
{Explanation which goes over two coloums}\\
\hline
\multirow{3}{*}{Targets}
& Target 1 is long text with two lines & not reached\\
\cline{2-3}
& Target 2 & reached\\
\cline{2-3}
& Target 3 & reached\\
\hline
\end{tabular}%
}
\label{tab:test}%
\end{table}%
我希望这张照片有助于理解我的问题:
我想将文本“目标”对齐到单元格顶部,就像第二个表格一样。我相信这应该很简单,但我似乎无法确定。
答案1
使用\multirow
(来自multirow
包裹)将内容推到行的中间3
。相反,只需放弃使用\multirow
即可使单元格顶部对齐:
\documentclass[12pt]{article}
\usepackage{graphicx}% http://ctan.org/pkg/graphicx
%\usepackage{multirow}% http://ctan.org/pkg/multirow
\usepackage{calc}% http://ctan.org/pkg/calc
\begin{document}
\begin{table}[!ht]
\centering
\caption{Titel}
\resizebox{.95\columnwidth}{!}{%
\begin{tabular}{p{4.5cm}p{10cm}p{3.5cm}}
\hline
Name & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
{long title which goes over two columns}\\
\hline
Explanation & \multicolumn{2}{p{\textwidth-3\tabcolsep-\widthof{test}-2\fboxrule}}
{Explanation which goes over two columns}\\
\hline
Targets % Don't use \multirow{4}{*}{Targets} here
& Target 1 is long text with two lines exactly like this spans two lines & not reached\\
\cline{2-3}
& Target 2 & reached\\
\cline{2-3}
& Target 3 & reached\\
\hline
\end{tabular}%
}
\label{tab:test}%
\end{table}
\end{document}
答案2
这很容易处理新更新的多行命令有一个选项可以指定垂直文本对齐方式;将[t]
用于顶部对齐。
在您的示例中,您可以这样写:
\multirow[t]{3}{*}{Targets} & Target 1 is long text with two lines & not reached\\
以下是应产生所需输出的代码:
\begin{table}[!h]
\centering
\caption{Title}
\begin{tabular}{lll}
\hline
Name & \multicolumn{2}{l}{long title which goes over two columns}\\
\hline
Explanation & \multicolumn{2}{l}{Explanation which goes over two columns}\\
\hline
\multirow[t]{3}{*}{Targets} & Target 1 is long text with two lines & not reached\\
\cline{2-3}
& Target 2 & reached\\
\cline{2-3}
& Target 3 & reached\\
\hline
\end{tabular}%
\label{tab:test}%
\end{table}
附言:不要忘记添加多行包。
答案3
无需明确指定列的宽度,而是使用l
说明符(可能需要数组包)。其用法的一个示例如下
\begin{center}
\begin{tabular}{ | l | l | l | p{5cm} |}
\hline
Day & Min Temp & Max Temp & Summary \\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells
across most of Scotland and Northern Ireland,
but rain reaching the far northwest. \\ \hline
Wednesday & 10C & 21C & Rain will still linger for the morning.
Conditions will improve by early afternoon and continue
throughout the evening. \\
\hline
\end{tabular}
\end{center}
这将提供如下输出
注意所有列的顶部对齐。
我希望这有帮助。
答案4
因为我有嵌套表格,所以我也遇到了同样的问题。我看到其他人已经解决了这个问题,所以我逐字逐句地重申了他们的答案——但强调了表格——因为本页上的其他解决方案在多行内定位表格时都不太管用。
\multirow{2}{*}[2em]{\vfil <insert table here>}