2

I'm having trouble getting the text in the multirow column vertically aligned at the center.

\documentclass{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}

\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{tabular}{c c c c}
\toprule

\multicolumn{3}{c}{\bfseries Heading 1}
    & \bfseries Heading 2
    \\

\cmidrule(r){1-3}
\cmidrule(l){4-4}

l
    & \multicolumn{1}{m{8em}}{
        or,
        em,
        ip,
        su,
        md,
        ol,
        or,
        si,
        ta,
        m,
        e
    }
    & \multirow{2}{*}{t}
    & \multicolumn{1}{m{8em}}{%
        \multirow{2}{=}{%
            con,
            sec,
            tet,
            ur,
            ad,
            ip,
            is,
            ci,
            ng,
            e,
            l,
            i,
            t
        }}
    \\

\cmidrule{1-2}

n
    & \multicolumn{1}{m{8em}}{%
        un,
        ca,
        ts,
        em,
        se,
        do,
        rc,
        ib,
        la,
        nd,
        it
    }
    & % t
    & % <Heading 2>
    \\

\bottomrule
\end{tabular}
\label{tab:table1}
\end{table}

\end{document}

The 3rd and 4th column of this table should be vertically aligned at the center but doesn't appear quite to be. Instead, it's shifted a little to the top. The same thing happens when I use a minipage instead of multicolumn over the single column.

enter image description here

3 Answers 3

2

An alternative approach using nicematrix:

enter image description here

\documentclass{article}

\usepackage{booktabs}
\usepackage{nicematrix}

\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{NiceTabular}{c m{8em} c m{8em}}
\toprule

\Block{1-3}{\bfseries Heading 1} &&& \Block{1-1}{\bfseries Heading 2}
    \\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & or, em, ip, su, md, ol, or, si, ta, m, e 
    & \Block{2-1}{t}
    & \Block{2-1}{\parbox{8em}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t}}
    \\
\cmidrule{1-2}
n & un, ca, ts, em, se, do, rc, ib, la, nd, it 
    & % t
    & % <Heading 2>
    \\
\bottomrule
\end{NiceTabular}
\label{tab:table1}
\end{table}

\end{document} 
1

In a \multirow, you should take into account the number of lines (4 here), and not the number of rows, as it was designed for single-lined cells. So I propose this, with a corrective argument, due to the booktabs rules, which add some vertical padding above and below its rules. I also loaded the caption package, to have a decent spacing between caption and table.

To centre the \multirow in the last column, instead of using 4 and corrective argument, I used another possibility: a non-integer number of lines (3.3).

\documentclass{article}

\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{caption}

\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{tabular}{c c c c}
\toprule

\multicolumn{3}{c}{\bfseries Heading 1}
    & \bfseries Heading 2
    \\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & \multicolumn{1}{m{8em}}{or, em, ip, su, md, ol, or, si, ta, m, e }
    & \multirow{4}{*}[1ex]{t}
    & \multicolumn{1}{m{8em}}{%
        \multirow{3.3}{=}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t }}
    \\
\cmidrule{1-2}
n & \multicolumn{1}{m{8em}}{un, ca, ts, em, se, do, rc, ib, la, nd, it }
    & % t
    & % <Heading 2>
    \\
\bottomrule
\end{tabular}
\label{tab:table1}
\end{table}

\end{document} 

enter image description here

2
  • "ad, ip, is,..." is currently shifted a bit upwards if compared to the "t" in the third column. You probably want to use \multirow{4}{=}[1ex]{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t } instead of \multirow{2}{=}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t }.
    – leandriis
    Commented Apr 4, 2021 at 9:09
  • @leandriis: you're right. Idon't don't why I overlooked this part of the result and focused essentially on the placement of the t. However, the value 4 did not look quite fine, and I took the opportunity to use the other method for fine-tuning the position: a number of lines with a decimal part. Thank you for pointing the problem!
    – Bernard
    Commented Apr 4, 2021 at 10:27
1

Here is a solution with recent version of nicematrix (≥ 6.0).

\documentclass{article}
\usepackage{booktabs,nicematrix}

\begin{document}
\begin{table}
\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\begin{NiceTabular}{c m{8em} c m[c]{8em}}
\toprule
\RowStyle{\bfseries}
\Block{1-3}{Heading 1} &&& Heading 2
    \\
\cmidrule(r){1-3}
\cmidrule(l){4-4}
l & or, em, ip, su, md, ol, or, si, ta, m, e 
    & \Block{2-1}{t}
    & \Block[l]{2-1}{con, sec, tet, ur, ad, ip, is, ci, ng, e, i, t}
    \\
\cmidrule{1-2}
n & un, ca, ts, em, se, do, rc, ib, la, nd, it 
    & % t
    & % <Heading 2>
    \\
\bottomrule
\end{NiceTabular}
\label{tab:table1}
\end{table}

\end{document} 

Output of the above code

You must log in to answer this question.

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