0

I am trying to join the rows of table that contains parboxes and figures, but multirow doesn't seem to work. Could someone please help me? Below is a minimum working example. Thanks, Jorge.

UPDATE1: Note that I really need the extra vertical space above Fig. B (that's why I embed it in a \parbox).

UPDATE2: It seems the real problem is that \tabular or \multirow are unable to properly take into account the height of the tallest cell when it is defined by a \parbox. I have modified my example to show the problem.

NEW MINIMUM WORKING EXAMPLE:

\documentclass{article}
\usepackage{graphbox,graphicx,multirow,multicol,geometry,array}
\begin{document}

This works:\\
\begin{tabular}{|l|l|r@{}|}
    \hline
    blah & blah & \multirow{4}{*}{\fbox{Text}}\\
    \hline
    blah & blah & \\
    \hline
    blah & blah & \\
    \hline
    blah & blah & \\
    \hline
\end{tabular}

\vspace{1cm}
This doesn't work:\\
\begin{tabular}{|l|l|r@{}|}
    \hline
    blah & blah & \multirow{4}{*}{\fbox{\parbox[b][3cm][b]{1cm}{Text}}}\\
    \hline
    blah & blah & \\
    \hline
    blah & blah & \\
    \hline
    blah & blah & \\
    \hline
\end{tabular}

\end{document} 

OUTPUT:

enter image description here

OLD MINIMUM WORKING EXAMPLE:

\documentclass{article}    
\usepackage{graphbox}
\usepackage{graphicx}
\usepackage{multirow}

\begin{document}

% All separate rows
\noindent{}I want to join the rows in the last column of this table (keeping the bottom vertical alignment, so that the bottom of fig. B is now aligned with the "Some other text" line):\\

\begin{tabular}{|l|l|r|}
    \hline
    \parbox[t][][t]{4cm}{Some text}
    & \parbox[t][][t]{4cm}{
            Some text\\
            Some text\\
            Some text\\
            \\
            \includegraphics[width=3cm]{example-image-A}
        }
    &
        % I embed Fig. B in a parbox to create the artificial space above it!
        % (Also, why it's not aligned to the right, as specified in the tabular options?)
        \parbox[t][1cm][b]{5cm}{
        \includegraphics[align=t,width=4cm,height=4cm]{example-image-B}
        }
    \\
    \hline
    \small{Some other text} & &\\
    \hline
\end{tabular}

\vspace{1cm}

% Attempt to join rows in right-most column:
\noindent{}Using \emph{multirow} doesn't seem work:\\

\begin{tabular}{|l|l|r|}
    \hline
    \parbox[t][][t]{4cm}{Some text}
    & \parbox[t][][t]{4cm}{
            Some text\\
            Some text\\
            Some text\\
            \\
            \includegraphics[width=3cm]{example-image-A}
        }
    & \multirow{2}{*}{
        % I embed Fig. B in a parbox to create the artificial space above it!
        % (Also, why it's not aligned to the right, as specified in the tabular options?)
        \parbox[t][1cm][b]{5cm}{
        \includegraphics[align=t,width=4cm,height=4cm]{example-image-B}
        }
    }
    \\
    \hline
    \small{Some other text} & &\\
    \hline
\end{tabular}

\end{document} 

Output: enter image description here

UPDATE: @Bernard proposed a workaround by tweaking the height of a neighboring cell (see below), which suited my particular need. The original problem (multirow cell height adjustment with \parbox elements) remains unsolved, though.

\documentclass{article}
\usepackage{graphbox}
\usepackage{graphicx}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{geometry}
\usepackage{array}

\begin{document}
\setlength{\extrarowheight}{2pt}
\begin{tabular}{|l|l|r@{}|}
        \hline
        \parbox[t][][t]{4cm}{Some text}
        & \parbox[t][][t]{4cm}{
                Some text\\
                Some text\\
                Some text\\
                \\
                \includegraphics[width=3cm]{example-image-A}\\[1.5cm]
            }
        &
        \\
        \cline{1-2}
        \small{Some other text} & & \multirow{-8.4}{*}{\includegraphics[align=b,width=4cm,height=4cm]{example-image-B}}\\
        \hline
\end{tabular}
\end{document}

OUTPUT:

enter image description here

1 Answer 1

1

Here is a simple solution with multirow. You must be aware that the no of rows as an argument for the environment, is actually rather the number of lines, i.e. n = no of rows is valid for one-line cells. Also, the graphics is indeed right aligned, as you can see when the last tabcolsep is deleted.

\documentclass{article}
\usepackage{geometry}
\usepackage{graphbox}
\usepackage{graphicx}
\usepackage{array, multirow}

\begin{document}

\setlength{\extrarowheight}{2pt}
\begin{tabular}{|l|l|r@{}|}
    \hline
    \parbox[t][][t]{4cm}{Some text}
    & \parbox[t][][t]{4cm}{
            Some text\\
            Some text\\
            Some text\\[1.5cm]
           % \\
            \includegraphics[width=3cm]{example-image-A}
        }
    &
    \\
    \cline{1-2}
    \small{Some other text} & & \multirow{-8.4}{*}{\includegraphics[align=b,width=4cm,height=4cm]{example-image-B}}\\
    \hline
\end{tabular}

\end{document} 

enter image description here

6
  • Thanks for your reply, @Bernard. Unfortunately this is not solving the problem, as I really need the space above figure B (that's why I use the \parbox). If I embed the figure again in a parbox, you can see that the problem persists (see updated question)
    – dontpanic
    Apr 20, 2018 at 8:43
  • I guess the real question is "Why aren't \tabular or \multirow calculating the heights of the cells according to the height of the tallest cell (i.e. the \parbox enclosing Fig. B)?"
    – dontpanic
    Apr 20, 2018 at 8:45
  • 1
    @dontpanic: each row height is adapted to its cells content, but multirow works fine with surrounding one-line cells, so that in the case of multiline cells, you have to guess by trial and error an equivalent number of rows. That said, to add a space above image B, one can add an invisible rule in the first cell of the first row, see my modified code and the result if it corresponds to what you want. However with this solution, I don't get what's the usefulness of the \ parboxes
    – Bernard
    Apr 20, 2018 at 9:28
  • Thanks again, Bernard. That's closer to what I intended, but now the text in the 1st and 2nd columns also moved down!. I've tried putting the rule just before the Fig. B instantiation, but things seem to break again (see updated code)
    – dontpanic
    Apr 20, 2018 at 10:08
  • 1
    @dontpanic: And like this? In the place of the invisible rule, I played with the optional argument of \\ in the second column (code updated).
    – Bernard
    Apr 20, 2018 at 10:26

You must log in to answer this question.

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