2010-10-21 52 views
27

我無法找到如何在表格中打開多行內部的線條。我需要製作一張桌子,我有一個單元格,它有兩排高度,我有很長的文字,但它不會折斷線條,文字與左側的另一個單元格重疊。乳膠:如何打破錶格內的多行內部線條

有什麼建議嗎?

示例代碼:

\begin{center} 
    \begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|} 
    \hline 
    \multirow{2}{*}{Long text to break} % HERE IS A PROBLEM 
     & Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}  
    \\ \cline{2-6} 
     & sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline 
\hline 
\end{tabular} 
\end{center} 

回答

9

你可以嘗試minipage它:

\begin{center} 
\begin{tabular}{|l|l|l|l|l|l|} 
    \hline 
    \multirow{2}{*}{\begin{minipage}{0.5in}Long text to break\end{minipage}} 
    & Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\ 
    \cline{2-6} 
    & sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ 
    \hline 
    \hline 
\end{tabular} 
\end{center} 

然而,在特定情況下,我的建議將僅僅是放鬆的限制其他專欄,因爲那裏浪費的空間太多。每個p{}都會強制其他列的寬度是一定的,所以第一列沒有足夠的空間。

下面的代碼看起來像樣我,當我編譯它:

\begin{center} 
\begin{tabular}{|l|l|l|l|l|l|} 
    \hline 
    \multirow{2}{*}{Long text to break} 
    & Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\ 
    \cline{2-6} 
    & sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ 
    \hline 
    \hline 
\end{tabular} 
\end{center} 
+0

我不能在表格命令中使用「l」參數,因爲單元格的寬度是「\ begin {minipage} {2cm}長的文本要打破\ end {minipage}「幫助我,謝謝。 – kokosing 2010-10-21 21:18:10

30

p柱和\parbox也適用:

\usepackage{multirow} 

\begin{document} 
\begin{center} 
\begin{tabular}{|p{1.5cm}|l|l|l|l|l|} 
    \hline 
    \multirow{2}{*}{\parbox{1.5cm}{Long text to break}} 
    & Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3} \\ 
    \cline{2-6} 
    & sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ 
    \hline 
    \hline 
\end{tabular} 
\end{center} 
\end{document} 

parbox in latex document

+0

謝謝,對我很好。但是,我認爲你應該使用'\ parbox'而不是TeX'\ vbox' – 2014-01-17 02:02:29

+0

謝謝!我已經更新了答案。 Parbox處理文本上方的空間。 – Tombart 2014-01-17 09:15:25

6

對我來說它的工作使用的生成-in命令「multirow」 - {*}是「{width}」

9

對我來說最短和最實用的答案:

使用\linewidth爲長度爲{width}參數。

\usepackage{multirow} 
\begin{document} 

\begin{center} 
\begin{tabular}{|p{1cm}|p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{2cm}|} 
\hline 
\multirow{2}{\linewidth}{Long text to break} % HERE IS A PROBLEM 
    & Thing & \multicolumn{2}{|c|}{Thing 2} & \multicolumn{2}{|c|}{Thing 3}  
\\ \cline{2-6} 
    & sth 1 & sth 1 & sth 2 & sth 1 & sth 2 \\ \hline 
\hline 
\end{tabular} 
\end{center} 

\end{document} 

就是這樣!

唯一可能出現的問題是,在不可能的情況下,在其他單元格的文本是非常短的,可能看起來像: Broken text in the right width but sadly going out of the table

但是,如果通常你的表在其他細胞大於文本只是「sth1」它看起來不錯: enter image description here

+1

如何防止多行列中的溢出? – Midiparse 2015-12-19 11:02:40

+0

@Midiparse對不起,我無法給你答案。一種可能性可能是把你的文本放在一個盒子裏,並在多行環境中使用這個盒子[只是猜測(!)] – 2015-12-27 12:10:49