longtable 和 multirow 的更多问题

longtable 和 multirow 的更多问题

在我之前的问题中,有几个解决方法可以解决我当前的问题。但是,我感觉这两个包不能很好地协同工作。再添加一列并在不同的行集上设置多行会使解决方法不起作用。

以下是代码:

\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}

相关内容