6

I'am trying to align the first multirow column vertically centered. Unfortunately multirow does not determine the actual height. Instead it aligns the multirow it based on the height of three single lined rows. Here is a small example which demonstrates the problem. Any ideas how to solve this issue?

\documentclass{article}
\usepackage{tabularx, multirow, blindtext}

\begin{document}
  \begin{tabularx}{\textwidth}{cX}
    \multirow{3}{*}{C} & \blindtext \\
                       & \blindtext \\
                       & \blindtext \\
   \end{tabularx}
\end{document}
4

Perhaps you over-simplified the setup. However, here's an easy way to obtain the vertical alignment:

enter image description here

\documentclass{article}
\usepackage{tabularx, blindtext}

\begin{document}

\noindent
\makebox[3em]{C}%
\begin{tabularx}{\dimexpr\linewidth-3em}{X}
  \blindtext \\
  \blindtext \\
  \blindtext
\end{tabularx}
\end{document}

The above uses the fact that a tabular-like construction is always centred vertically with respect to the surrounding content, but also assumes the following:

  • you don't want to break the table across the page boundary (this assumption holds since you're using tabularx);

  • you specify some manual width for the first "column" (although this could also be overcome using some box calculation, if needed);

  • you don't use multi-line stuff in the first "column" (again, this can also be overcome by using a \parbox, say).

3

See

http://chat.stackexchange.com/search?q=multirow&user=11727&room=41

for thoughts on multirow alignment, but if you really want to centre the C you can use \raisebox to lower it by half the distance between the first and last baselines:

enter image description here

(This takes two passes of latex)

\documentclass{article}
\usepackage{tabularx,blindtext}

\makeatletter
\def\z#1{%
\pdfsavepos\write\@auxout{\global\noexpand\@namedef{pos@#1}{\the\pdflastypos}}}

\def\pos@start{0}
\def\pos@end{0}
\begin{document}


\noindent
  \begin{tabularx}{\textwidth}{cX}
    C & \blindtext \\
                       & \blindtext \\
                       & \blindtext \\
   \end{tabularx}


\noindent
  \begin{tabularx}{\textwidth}{cX}
    \smash{\raisebox{0.5\dimexpr
\pos@end sp - \pos@start sp
\relax}{C}} & \z{start}\blindtext \\
                       & \blindtext \\
                       & \blindtext\z{end} \\
   \end{tabularx}




\end{document}
  • You're closer with \raisebox{0.5\dimexpr\pos@end sp - \pos@start sp-\normalbaselineskip}[0pt][0pt]{C}... – Werner Jan 3 '15 at 1:41
  • @Werner It depends what you mean by "centre" if the para on the right is three lines it probably looks best to put the baseline of C on the baseline of the middle line, even though the height of the top row is typically more than the depth of the last row – David Carlisle Jan 3 '15 at 1:49
2

You have to count the exact number of lines of the adjacent cells. By default, multirow seems to suppose adjacent cells are one-lined.

Anoher solution (if you use the Xspecifier in true life) can be to not use multirow, and redefine the X specifier as an m column type:

\documentclass{article}
\usepackage{tabularx, multirow, blindtext}


\begin{document}

  \begin{tabularx}{\textwidth}{cX}
    \multirow{33}{*}{C} & \blindtext \\
                       & \blindtext \\
                       & \blindtext \\
   \end{tabularx}

{\renewcommand{\tabularxcolumn}[1]{m{#1}}
 \begin{tabularx}{\textwidth}{cX}
    & \blindtext \\
     Q & \blindtext \\
    & \blindtext \\
   \end{tabularx}}
\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.