0

in my previous question there were a couple of workarounds that solved my immediate issue. However, I have the feeling that those two packages do not work well together. Adding one more column and having multirows on different set of rows make the workarounds not working.

Here is the code:

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

And the result is clearly not good. Any help in finding a generic solution to this problem would be very appreciated.

output of previous code

  • 2
    It has nothing to do with longtable, you get the same result with tabular. You might have the wrong idea about what \multirow actually does. Let me ask another way: that exactly are you trying to achinve here? – daleif Aug 20 at 12:21
  • This issue is discussed in Section 3.8 "Dealing with tall entries" of the multirow package documentation, mirrors.ctan.org/macros/latex/contrib/multirow/multirow.pdf where manual solutions are proposed. – ebcontrol Aug 20 at 12:41
  • 1
    In particular, read the manual section 3.8 item 2: 2. The second case is when the \multirow entry is taller than the surrounding normal rows. In that case the multirow text will stick out of its block. We must now enlarge the other rows, and that is something \multirow cannot do. – Sveinung Aug 20 at 13:13
  • I don't understad what you're trying to achieve suing \multirow. You don't really have to use it, unless… Could you pst a small sketch of what you want to obtain? – Bernard Aug 20 at 14:13
  • Could you please add a sketch of what you want to achieve. Maybe a more "real life" example could also be helpful. – leandriis Aug 20 at 17:53
3

The answer to your previous (almost the same) question solves your problem. If not, your question is not clear.

Adoption of @sveinung's answer:

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

Note: \multirow[<number of rows>{...}{cell's contents} doesn't determine its height with number of rows (which it contain). It spans the given number of lines in adjacent column. If their height is smaller than height of the multirow cell, then its contents will spill out on the adjacent cells as you observe in your question.

Please, read the package documentation as @ebcontrol suggests in his comment.

Edit: The column width is nowcorrected and the width of the longtable is exactly \textwidth.

  • 1
    @Sveinung, thank you for editing my answer. Unfortunately we doing this in the same time (beside misspelling of you name I notice some other errors in code and that my explanation wasn't uploaded. – Zarko Aug 20 at 13:17
0

NB I have updated the code for example 2

I use shorter dummy texts so the examples are more readable. Look at the two enclosed examples and tell us (me) how they deviate from what you try to achieve. In particular, example 2 demands manual work:

Example 1

enter image description here

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

Example 2

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.