5

I have long text in a multirow cell. And the text takes more rows than the rows in the second column.

\documentclass[a4paper,12pt]{report}
\usepackage{multirow}
\usepackage{longtable}

\begin{document}

\begin{longtable}[H]{|p{\dimexpr0.5\linewidth-2\tabcolsep}|p{\dimexpr0.5\linewidth-2\tabcolsep}|}
\caption{Title}
\tabularnewline\hline
\multirow{2}{\linewidth}{\centering \tiny \textbf{Long long  long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text}} & \tiny 11 \tabularnewline \cline{2-2}
 & \tiny 11 \tabularnewline \cline{1-2}
\end{longtable}

\end{document}

I get this: enter image description here

How can I fix it? I generate table automatically, and I do not know how many lines of text in the multirow cell takes. So I can not manually add blank lines in the second column.

Update for Bernard When I compile this code:

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}

\usepackage{multirow}
\usepackage{longtable}

\usepackage{makecell}

\begin{document}

\begin{longtable}{|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|}
\caption{Title}
\tabularnewline\hline%
\multirow{2}{*}{\parbox{\linewidth}%[24pt]
{\centering \scriptsize \textbf{Long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long}}}
& \Gape[12pt]{\scriptsize 11} \tabularnewline
\cline{2-2}
& \Gape[12pt]{\scriptsize 11} \tabularnewline
 \cline{1-2}
\end{longtable}\bigskip

{\normalsize
\begin{longtable}{|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|}
\caption{Title}
\tabularnewline\hline%
\multirowcell{8}{\parbox{\linewidth}
{\centering \textbf{Long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long}}}
&\multirowcell{4}{11} \tabularnewline & \tabularnewline & \tabularnewline & \tabularnewline
\cline{2-2}
& \multirowcell{4}{11} \tabularnewline & \tabularnewline & \tabularnewline & \tabularnewline
 \cline{1-2}
\end{longtable}
}
\end{document} 

I see this result: enter image description here enter image description here

4
  • 1
    Not a full answer, just a couple of suggestions. First, f everything in the longtable is going to be set in \tiny size (at least that's the way it looks in your MWE), it may be best to provide that directive before the start of the longtable environment; otherwise you'll get serious problems with baselines not lining up. Second, have you thought about inserting "struts" (invisible vertical bars) in the cells of the second column?
    – Mico
    Commented Jun 1, 2014 at 14:57
  • I agree about the moment with tiny. I do not know how much you need to add an empty space in the second column. Table is generated automatically in the program.
    – Harrix
    Commented Jun 1, 2014 at 15:05
  • 1
    Does the program output change every time, or is it fixed from run to run?
    – Mico
    Commented Jun 1, 2014 at 15:12
  • Сhange every time. I do not know in advance the contents of cells. The length of the text of each may be different. The optimal solution would be to have a multirow cell automatically stretched to the content.
    – Harrix
    Commented Jun 1, 2014 at 15:16

2 Answers 2

1

enter image description here

\documentclass[a4paper,12pt]{report}
\usepackage{multirow}
\usepackage{longtable,calc}

\newlength{\MyLength}

\newcommand{\Multirow}[3]{%
    \setlength{\MyLength}{%
        \heightof{
            \begin{minipage}[b]{#2}
            #3
            \end{minipage}
        }
    }
    \global\MyLength=\MyLength
    \multirow{#1}{#2}{#3}
}

\newcommand{\Myrule}[1][.5]{\rule[-#1\MyLength]{0pt}{0pt}}

\begin{document}

{\tiny
\begin{longtable}[H]{|p{0.5\linewidth-2\tabcolsep}|p{0.5\linewidth-2\tabcolsep}|}
\caption{Title}
\tabularnewline\hline
\Multirow{2}{\linewidth}{\centering \tiny \textbf{Long long  long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long text}} &
11 \Myrule[.55]\tabularnewline \cline{2-2}
 & 11 \Myrule[.3]\tabularnewline \cline{1-2}
\end{longtable}
}

\end{document}
3
  • Good decision, but the decision should be set variable \MyLength manually. Can we find \MyLength if we know text in cell?
    – Harrix
    Commented Jun 1, 2014 at 18:20
  • 1
    It is precisly my problem. The \Multirow command should set \Mylength with the heigt of the cell. I asked how to use it globally. Then you don't have to set it manually.
    – Tarass
    Commented Jun 1, 2014 at 18:46
  • 1
    Ok, I find how to have a global length.
    – Tarass
    Commented Jun 1, 2014 at 19:43
4

A solution could be to use the \Gape command (from the makecell package) to increase the height of the cells in the second column that correspond to the \multirow in the first column. The value of the optional argument has to be determined experimentally, as it depends on the font/ fontsize. You also have to put the long text in a \parbox inside multirow.

Another solution, also with makecell consists in making both cells in the second column \multirowcells, of the (same) relevant number of rows, and the long text a \multirowcell of twice this number of rows.

Both solutions are illustrated in the following code:

\documentclass[a4paper,12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{fourier}

\usepackage{multirow}
\usepackage{longtable}

\usepackage{makecell}

\begin{document}

\begin{longtable}{|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|}
\caption{Title}
\tabularnewline\hline%
\multirow{2}{*}{\parbox{\linewidth}%
{\centering \scriptsize \textbf{Long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long}}}
& \Gape[12pt]{\scriptsize 11} \tabularnewline
\cline{2-2}
& \Gape[12pt]{\scriptsize 11} \tabularnewline
 \cline{1-2}
\end{longtable}\bigskip

{\normalsize
\begin{longtable}{|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|m{\dimexpr0.5\linewidth-2\tabcolsep\relax}|}
\caption{Title}
\tabularnewline\hline%
\multirowcell{8}{\parbox{\linewidth}
{\centering \textbf{Long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long long}}}
&\multirowcell{4}{11} \tabularnewline & \tabularnewline & \tabularnewline & \tabularnewline
\cline{2-2}
& \multirowcell{4}{11} \tabularnewline & \tabularnewline & \tabularnewline & \tabularnewline
 \cline{1-2}
\end{longtable}
}
\end{document} 

enter image description here

4
  • Is package \usepackage{fourier} nessesery? With this package, an error occurs. No service is no error, but the cell does not stretch.
    – Harrix
    Commented Jun 1, 2014 at 18:18
  • 1
    No, not at all, it's just there because I don't like Computer Modern. But of course, the numerical values will have to be adapted. However, what you tell me is strange. Did you compile the code alone, or did you use it in a document with its own preamble?
    – Bernard
    Commented Jun 1, 2014 at 18:24
  • I copy all code in new document and delete string \usepackage{fourier} only. I use TeXstudio 2.6.2 + MiKTeX 2.9 on Windows 7. In post I added screenshot of result code.
    – Harrix
    Commented Jun 1, 2014 at 18:38
  • 1
    I see. You'll have to increase the value in Gape for the first solution (16 pt?) and the number of rows for the second solution (one more should do the trick).
    – Bernard
    Commented Jun 1, 2014 at 19:33

You must log in to answer this question.

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