2

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.

Hereafter a minimum working code:

\documentclass{article}

\usepackage{longtable}
\usepackage {multirow}
\usepackage{lipsum}

\begin{document}

\begin{center}

\begin{longtable}{|p{.15\textwidth}|p{.15\textwidth}|p{0.65\textwidth}|}
    \hline  
    1 & 1.1 & \multirow{3}{.65\textwidth} {\lipsum[1] }\\
     & 1.2 & \\
     & 1.3 & \\ \hline  
     2 & 2.1 & \lipsum[2] \\ \hline  
     \end{longtable} 
    \end{center}

\end{document}

Any help is truly appreciated ...

1

1 Answer 1

1

I am still unsure what you are looking for, but based on your last comments regarding adding vspace, I am curious why you do not place the section number (1.1, 1.2 and 1.3) in the same cell i column 2. The cells in the third columns will then shrink and expand automatically if you add or delete text. If you have rows where two sections contain text, you place that section in a separate row, see example 2.

Two additional improvements:

  1. Remove the centering-environment. longtable is centred by default, and use its own alignment algorithm (see documentation)
  2. Calculate the rows by taking into account the influence of tabcolseps and the width of vertical rules, see the new preamble. If you have several similar tables, I recommend that you load array and define two new column-types using \newcolumntype, which you then may use in the your tables’ preambles:

\newcolumntype{M}{p{\dimexpr(0.175\linewidth-2\tabcolsep-1.5\arrayrulewidth)}}
\newcolumntype{N}{p{\dimexpr(0.65\linewidth-2\tabcolsep-\arrayrulewidth)}}

The preamble for the first tabular:

 \begin{longtable}{|M|M|N|}

enter image description here

\documentclass{article}

\usepackage{longtable}
\usepackage{lipsum, array}

\begin{document}

\begin{longtable}{
|p{\dimexpr(0.175\linewidth-2\tabcolsep-1.5\arrayrulewidth)}
|p{\dimexpr(0.175\linewidth-2\tabcolsep-1.5\arrayrulewidth)}
|p{\dimexpr(0.65\linewidth-2\tabcolsep-\arrayrulewidth)}|}
\hline  
1 & 1.1 \par 1.2\par 1.3 & \lipsum[1]\\\hline  
 2 & 2.1 & \lipsum[2] \\ \hline  
 \end{longtable} 
\end{document}

For certain, I would have chosen a different layout, using booktabs rules and no vertical rules.

enter image description here

\documentclass{article}

\usepackage{longtable}
\usepackage{lipsum, array}

\newcolumntype{O}{p{\dimexpr(0.175\linewidth-1.5\tabcolsep)}}
\newcolumntype{P}{p{\dimexpr(0.65\linewidth-\tabcolsep)}}

\begin{document}

\begin{longtable}{@{}OOP@{}}
    \toprule \addlinespace[1ex]
    1 & 1.1 \par 1.2\par 1.3 & \lipsum[1]\\\midrule  \addlinespace[1ex]
    2 & 2.1 & \lipsum[2] \\\cmidrule(l{\tabcolsep}){3-3}
      & 2.2\par 2.3 & \lipsum[2] \\ \midrule
     \end{longtable}

\end{document}
5
  • Well, I only have 3 subsection, not 19, or 40. So I'm sorry but this answer does not really help my case. As well, I know that adding a \vspace () makes the table look correct, but I wonder if there is a better/nicer way to get this done? () -> \vspace{6.8cm} & 1.3 & \\ \hline
    – alex b
    Commented Aug 20, 2019 at 6:27
  • @alexb If you describe what you are looking for, maybe you can get better answers. "...but I wonder if there is a better/nicer way to get this done? " was not what you asked for in your question. (More precisely, you did not ask a questions at all!)
    – Sveinung
    Commented Aug 20, 2019 at 7:07
  • in my example the text in the third column goes well over the multirow. As I have only 3 subsections and a description that is for the three of them, I simply cannot add a random number of lines (or subsection) as in your answer, to make the last cell fit. One solution I've found is to use \vspace, but it's a hack as every time I change the text I need to update the space manually. So I am wondering if anyone knows a proper solution, where from proper I mean that LaTeX automatically put the following row below the content of the last cell.
    – alex b
    Commented Aug 20, 2019 at 7:34
  • Thanks! the reason why I had different rows is because the table is quite long, repeated 16 times, so I was using the same layout and adding the text in the last column. In most cases the text is different for every line but in a few places has to be merged together. Indeed I can change the few times where it happens so I don't have this issue.
    – alex b
    Commented Aug 20, 2019 at 10:49
  • @alexb I have updated the code and added some additional tips to simplify the code. If the answer has been to help, consider to accept the it, and eventually upvote. If it has been of no help, I will consider deleting it.
    – Sveinung
    Commented Aug 20, 2019 at 12:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .