
在我之前的問題中,有一些解決方法可以解決我眼前的問題。但是,我感覺這兩個包不能很好地協同工作。新增一列並在不同的行集中新增多行會使解決方法無法運作。
這是代碼:
\documentclass{article}
\usepackage{longtable}
\usepackage {multirow}
\usepackage{lipsum}
\begin{document}
\begin{center}
\begin{longtable}{p{.15\textwidth} p{.15\textwidth} p{0.32\textwidth} p{0.32\textwidth}}
\hline
1 & 1.1 & \multirow{2}{.32\textwidth} {\lipsum[1] } & some text \\ \cline{4-4}
& 1.2 & & \multirow{2}{.32\textwidth}{\lipsum[2]} \\ \cline{2-3}
& 1.3 & some other text & \\ \hline
2 & 2.1 & some more text & \lipsum[3] \\ \hline
\end{longtable}
\end{center}
\end{document}
而結果顯然並不好。任何幫助找到此問題的通用解決方案的幫助將不勝感激。
答案1
您上一個(幾乎相同)問題的答案解決了您的問題。如果沒有,那你的問題不清楚。
採用@sveinung 的回答:
\documentclass{article}
\usepackage{makecell, longtable}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\begin{longtable}{|p{\dimexpr0.07\textwidth-2\tabcolsep-1.25\arrayrulewidth}
|p{\dimexpr0.07\textwidth-2\tabcolsep-1.25\arrayrulewidth}
|p{\dimexpr0.43\textwidth-2\tabcolsep-1.25\arrayrulewidth}
|p{\dimexpr0.43\textwidth-2\tabcolsep-1.25\arrayrulewidth}
|}
\hline
1 & 1.1 & \lipsum[1] & some text \\ \cline{2-4}
& 1.2 & & \lipsum[2] \\ \cline{2-4}
& 1.3 & some other text & \\
\hline
2 & 2.1 & some more text & \lipsum[3] \\
\hline
\end{longtable}
\end{document}
筆記: \multirow[<number of rows>{...}{cell's contents}
不根據行數(它包含的行數)確定其高度。它跨越相鄰列中給定的行數。如果它們的高度小於multirow
單元格的高度,那麼正如您在問題中觀察到的那樣,其內容將溢出到相鄰的單元格上。
請按照 @ebcontrol 在他的評論中建議的方式閱讀包文檔。
編輯:列寬現在已修正,寬度longtable
剛好為\textwidth
。
答案2
注意我已經更新了範例2的程式碼
我使用較短的虛擬文本,因此範例更具可讀性。看看隨附的兩個範例,並告訴我們(我)它們如何偏離您試圖實現的目標。特別是,範例 2 需要手動操作:
實施例1
\documentclass{article}
\usepackage{longtable, booktabs, array}
\usepackage{lipsum}
\newcolumntype{O}{p{\dimexpr(0.15\linewidth-1.5\tabcolsep)}}
\newcolumntype{Q}{p{\dimexpr(0.35\linewidth-1.5\tabcolsep)}}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\newcommand{\mytexti}{This is a dummy text, however I have an issue using multirow and longtable. The content in the multirow cell is very large, and it goes well beyond the limit of the "non-multirowed" rows. LaTeX ignores that and starts the following row just behind those rows, therefore overwriting the content.}
\newcommand{\mytextii}{This is a shorter dummy text, LaTeX ignores me!}
\begin{document}
\begin{longtable}{@{}OOQQ@{}}
\toprule\addlinespace[1ex]
1 & 1.1 & \mytexti & some text \\ \cmidrule{4-4}
& 1.2 & & \mytextii \\ \cmidrule{3-3}
& 1.3 & some other text & \\ \bottomrule \addlinespace[1ex]
2 & 2.1 & some more text & \mytexti \\ \bottomrule
\end{longtable}
\end{document}
實施例2
\documentclass{article}
\usepackage{longtable, booktabs, array, multirow, bigstrut}
\usepackage{lipsum}
\newcolumntype{O}{p{\dimexpr(0.15\linewidth-1.5\tabcolsep)}}
\newcolumntype{Q}{p{\dimexpr(0.35\linewidth-1.5\tabcolsep)}}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\newcommand{\mytexti}{This is a dummy text, however I have an issue using multirow and longtable. The content in the multirow cell is very large, and it goes well beyond the limit of the "non-multirowed" rows. LaTeX ignores that and starts the following row just behind those rows, therefore overwriting the content.}
\newcommand{\mytextii}{This is a shorter dummy text, LaTeX ignores me!}
\begin{document}
\begin{longtable}{@{}OOQQ@{}}
\toprule\addlinespace[1ex]
1 & & \mytexti & some text\strut \hrule \\
& \multirow[t]{-14}{=}{1.1\\ 1.2} & some other text & \multirow[t]{-12.9}{=}{\mytextii} \\ \cmidrule{3-3}
& 1.3 & some other text & \\
\bottomrule \addlinespace[1ex]
2 & 2.1 & some more text & \mytexti \\ \bottomrule
\end{longtable}
\end{document}