我遇到以下代码的问题:
\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}%
我希望这张照片有助于理解我的问题:
我想将单元格顶部的文本“Targets”对齐,就像第二个表格一样。我敢肯定这一定很简单,但我似乎无法将手指放在上面。请帮我解决这个问题。
答案 0 :(得分:1)
不是明确指定列的宽度,而是使用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}
这将提供这样的输出
请注意所有列的顶部对齐方式。
我希望这会有所帮助。