2

Consider this example:

\documentclass{report}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{multirow}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
\begin{tabularx}{0.5\linewidth}{llX}
  \multirow{2}{*}{A} & B & \lipsum[1][1-2] \\
                     & C & \lipsum[2][1-3]\\
\end{tabularx}
\end{document}

The output is

enter image description here

I have used Vertical alignment in tabularx X column type to centre cells vertically.

However, I am not pleased the way "A" is centred. It uses multirow. How to centre "A" vertically in the middle of the table?

Solution that avoids the use of multirow is also accepted.

Viesturs
  • 7,895
  • Maybe you can try with \multirow{8}{*}{A}. – leandriis Apr 22 '19 at 08:18
  • Since you made m the underlying column type, since the cells in column 3 occupy 12 rows in all, and since one half of 12 is 6, you should replace \multirow{2}{*}{A} with \multirow{6}{*}{A}. – Mico Apr 22 '19 at 08:22
  • @Mico: Wouldn't one typically use \multirow{12} in order to vertically center a cell adjacent to a cell that contains 12 lines of text? However, in the OP's case the redefinition of the X type column using \renewcommand{\tabularxcolumn}[1]{m{#1}} seems to interfere with that. – leandriis Apr 22 '19 at 08:28
  • @leandriis, then I need to manually count rows. So laborious when dealing with many tables, changing text. – Viesturs Apr 22 '19 at 08:36
  • @leandriis - Indeed, if the \renewcommand{\tabularxcolumn}[1]{m{#1}} directive weren't there, one would have to use 12, not 6, as the first argument of \multirow. – Mico Apr 22 '19 at 08:40
  • @Mico, I checked using \multirow{6}.... There were 4 rows above and 5 below "A" - centring was not done nicely. 7 appear to do the job. – Viesturs Apr 22 '19 at 08:43
  • @Viesturs - The screenshot you posted shows a total of 12 rows, not 9 rows, for the cells in column 3. Using the code you posted, I also arrive at a total of 12 rows, not 9. Using your code and \multirow{6}..., the letter A is placed very nicely between the cells of column 3. Speaking purely aesthetically, that's exactly where the letter A belongs. Of course, if you've changed the code for the cells in column 3 in the meantime, there is absolutely no reason to believe that 6 will continue to be the appropriate argument for the first argument of \multirow. – Mico Apr 22 '19 at 08:49

3 Answers3

3

As Ulrike said in a comment, to avoid manual adjustment, nesting tabulars could be a solution.

I would put a tabular with an m column of appropriate width in the main tabular.

I added the lines just to show the "A" is vertically centered.

\documentclass{report}
\usepackage{tabularx}
\usepackage{array}
\usepackage{lipsum}
\begin{document}
\noindent\begin{tabular}{|ll}
\hline
  A & 
    \begin{tabular}{@{}lm{.352\linewidth}@{}}
        B & \lipsum[1][1-2]\\
        C & \lipsum[2][1-3]\\
    \end{tabular}\\
    \hline
\end{tabular}

\vspace{4ex}\noindent\begin{tabularx}{.5\linewidth}{|llX}
    \hline
    A & B & Just for benchmark\\
    \hline
\end{tabularx}
\end{document}

enter image description here

CarLaTeX
  • 62,716
3

Here is a possibe solution using a minipage and a tabularx:

\documentclass{report}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{multirow}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\usepackage{calc}

\begin{document}

\begin{minipage}{2em}
A
\end{minipage}%
\begin{tabularx}{0.5\linewidth-2em}{lX}
   B & \lipsum[1][1-2]  \\
   C & \lipsum[2][1-3]\\
\end{tabularx}

\end{document}

enter image description here

leandriis
  • 62,593
2

In this case you can use a 1-row multicolumn as the baseline of the m-column is there. In other cases you will have to use the vmode-option described in the documentation. Imho while multirow works okay with 1-line cells it is imho rather a pain with m- and p-columns and I use it seldom.

\documentclass{report}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{multirow}
\begin{document}
% with X as p-column 5 works:
\begin{tabularx}{0.5\linewidth}{llX}
  \multirow{5}{*}{A} & B & \lipsum[1][1-2] \\
                     & C & \lipsum[2][1-3]\\
\end{tabularx}

%X as m-column:
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{tabularx}{0.5\linewidth}{llX}
  \multirow{1}{*}{A} & B & \lipsum[1][1-2] \\
                     & C & \lipsum[2][1-3]\\
\end{tabularx}
\end{document}

enter image description here

To center the A over both cells use a value of 8.5 or 9 works (that's the number of lines below the baseline of the first cell.

\documentclass{report}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage{multirow}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
\begin{tabularx}{0.5\linewidth}{llX}
  \multirow{9}{*}{A} & B & \lipsum[1][1-2] \\
                     & C & \lipsum[2][1-3]\\
\end{tabularx}
\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Where is the improvement? Apparently I was not clear in my question, but by nicely I mean "A" centred vertically in the middle of the table. I updated my question. – Viesturs Apr 22 '19 at 08:39
  • Ah sorry, I added an edit. – Ulrike Fischer Apr 22 '19 at 08:51
  • Now there are 6 lines above and 5 below "A". 7 works for me. This solution requires a tedious counting of lines manually. – Viesturs Apr 22 '19 at 08:55
  • 1
    Yes, but the A is aligned to a line. It is up to you to decide what is visual more pleasing. And yes, it is a pain - I already wrote in the answer. I wouldn't use multirow but nested tabulars or even simple boxes for such a layout. – Ulrike Fischer Apr 22 '19 at 09:04
  • it could be worthwhile to provide your solution with nested tabulars or simple boxes. – Viesturs Apr 22 '19 at 09:06