3

I was following the instructions here and here to get a good looking table without the structure exceeding the bottom rule.

enter image description here

Both did not provide a solution. Is there a way to achieve this?

\documentclass[11pt]{article}

\usepackage[hmarginratio=1:1]{geometry}
\geometry{
    top=2cm,
    bottom=2.5cm,
    textwidth=7in}
\usepackage{graphicx} 
\usepackage{tabularx} 
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
    \begin{tabularx}{\textwidth}{lXlll}
        No. & Structure & Another Number & One More Number & Last Number\\
    \midrule
        \multirow{3}{*}{1
        } & \multirow{3}{*}{\includegraphics[width=4cm]{image}
        } & \multirow{3}{*}{1234
        } & 1   & 1 \\
        &&& 2   & 2 \\
        &&& 3   & 3 \\
    \bottomrule
    \end{tabularx}
\end{table}

\end{document}
1
  • Could you post the graphic file in use?
    – Bernard
    Jun 6, 2018 at 16:14

2 Answers 2

3

Instead of using multirow I suggest a single row and use \makecell in the last two columns, as this allows for line breaks in standard cells. I also redefine the X column type, so its content be vertically centred:

\documentclass[11pt]{article}

\usepackage[hmarginratio=1:1]{geometry}
\geometry{
    top=2cm,
    bottom=2.5cm,
    textwidth=7in}
\usepackage{graphicx, adjustbox}
\usepackage{tabularx}
\usepackage{multirow, makecell}
\usepackage{booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\arraybackslash}m{#1}}

\begin{document}

\begin{table}[h]
    \begin{tabularx}{\textwidth}{lXlll}
        No. & Structure & Another Number & One More Number & Last Number\\
    \midrule\addlinespace[1.5ex]
        1 & \includegraphics[width=4cm]{chemstructure} & 1234
        & \makecell[l]{1\\2\\3} & \makecell[l]{1\\2\\3} \\
    \bottomrule
    \end{tabularx}
\end{table}

\end{document} 

enter image description here

2
  • Would't this approach give problems when instead of just small numbers more text is available in a cell i.e. in a cell there are already automatic line breaks >
    – albert
    Jun 6, 2018 at 17:54
  • Maybe – but it's hard to say whatever in the absence of a real example. No one has to use make cell: it's only here because the l column type doesn't accept line breaks, and isn't required if the adjacent columns allow them. The basic idea is to use a single row if possible and avoid multirow in this context.
    – Bernard
    Jun 6, 2018 at 18:11
0

It seems to be a known problem that \multirow does not always properly calculate the height of cells that contain more than one line or at least gives unwanted results in certain circumstances (see para 3.8 on page 11 and following in the package documentation).

More precisely, the problem here seems to be that the \includegraphics macro itself sits in a multirow cell. As far as I understand the underlying calculations, the package measures the height of the rows to be spanned without taking into account any multirows cells. This, of course, yields a height of three cells containing only one line (namely the stuff in the last two columns of your table).

One possible workaround referred to in the package documentation (page 14) is to add an invisible \rule in one of the non-multirow cells of the last row, which is shifted downwards as much as is needed to stretch the relevant table row.

Example:

\documentclass[11pt]{article}

\usepackage[hmarginratio=1:1]{geometry}
\geometry{
    top=2cm,
    bottom=2.5cm,
    textwidth=7in}
\usepackage{graphicx} 
\usepackage{tabularx} 
\usepackage{multirow}
\usepackage{booktabs}

\begin{document}

\begin{table}[h]
    \begin{tabularx}{\textwidth}{lXlll}
        No. & Structure & Another Number & One More Number & Last Number\\
    \midrule
        \multirow{3}{*}{1
        } & \multirow{3}{*}{\includegraphics[width=4cm]{example-image-a}
        } & \multirow{3}{*}{1234
        } & 1   & 1 \\
        &&& 2   & 2 \\
        &&& 3   & 3 \rule[-50pt]{0pt}{0pt} \\
    \bottomrule
    \end{tabularx}
\end{table}

\end{document}

Yields:

enter image description here

You must log in to answer this question.

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