Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd appreciate advise in centering a multirow text. In the MWE below the multirow text "spring" is NOT centered over the three rows that it spans.

\documentclass[10pt,a4paper,twoside,open=right,headinclude,footinclude]{scrreprt}
\usepackage{classicthesis-ldpkg}
\usepackage{multirow}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table}[htbf]
 \centering
    \begin{tabular}{|M{20mm}|M{20mm}|M{20mm}|} \hline
        Type & Specs & Uses\\ \hline
        -- & Model 1 & blah blah blah blah blah blah blah blah \\ \hline
        \multirow{3}*{spring} & Model 2 & blah blah blah blah blah blah blah blah \\ \cline{2-3}
        & Model 3 & blah blah blah blah blah blah blah blah \\ \cline{2-3}
        & Model 4 & blah blah blah blah blah blah blah blah \\ \hline
    \end{tabular}
\end{table}

\end{document} 

multirow text not centered

However, in the trivial case where each entry in the table contains only one line, the multirow text is correctly centered as the following MWE shows:

\documentclass[10pt,a4paper,twoside,open=right,headinclude,footinclude]{scrreprt}
\usepackage{classicthesis-ldpkg}
\usepackage{multirow}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table}[htbf]
\centering
    \begin{tabular}{|M{20mm}|M{20mm}|M{20mm}|} \hline
        Type & Specs & Uses \\ \hline
        -- & Model 1 & blah \\ \hline
        \multirow{3}*{spring} & Model 2 & blah \\ \cline{2-3}
        & Model 3 & blah  \\ \cline{2-3}
        & Model 4 & blah \\ \hline
    \end{tabular}

\end{table}

\end{document}

multirow image centered

share|improve this question
add comment

5 Answers

I suggest that you also load the array package, as it'll help center (vertically) the contents of a cell; in fact, if you load this package, you needn't bother with multirow at all.

Separately, and identical to the thrust of egreg's answer, I would strongly recommend you use the booktabs package to get (much!) better vertical spacing above and below "rules" (horizontal lines), resulting in a much more "professional" look of your tables. In the code and image below, observe the use of the command \cmidrule{1-3} to draw a line across the entire width of the table with a thickness of "cmidrule" rather than the thickness of "midrule". Finally, for the the layout of your tabular material, I'd recommend using the ordinary "p" column type for columns 1 and 2 to get their contents left-justified. :-)

\documentclass{scrreprt}
\usepackage{classicthesis}    % I don't have "classicthesis-ldpkg" on my system...
\usepackage{array,booktabs}
\newcommand{\bla}{blah blah blah blah blah blah blah blah}
\newcolumntype{M}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{table}[ht]
  \centering
    \begin{tabular}{p{20mm}p{20mm}M{20mm}} \toprule
        Type   & Specs   & Uses \\ \midrule
        --     & Model 1 & \bla \\ \cmidrule{1-3}
               & Model 2 & \bla \\ \cmidrule(l){2-3}
        Spring & Model 3 & \bla \\ \cmidrule(l){2-3}
               & Model 4 & \bla \\ \bottomrule
    \end{tabular}
\end{table}
\end{document} 

enter image description here

share|improve this answer
add comment

This isn't an answer about \multirow, but rather a suggestion to use a different approach without vertical rules:

\usepackage{array,booktabs}

\begin{tabular}{ll>{\raggedright\arraybackslash}p{20mm}}
\toprule
Type & Specs & Uses \\
\midrule
       & Model 1 & \blah \\
\midrule
spring & Model 2 & \blah \\
\cmidrule{2-3}
       & Model 3 & \blah \\
\cmidrule{2-3}
       & Model 4 & \blah \\
\bottomrule
\end{tabular}

The interrupted horizontal rules make clear that "spring" applies to all entries in the same block delimited by full horizontal rules.

enter image description here

share|improve this answer
    
I don't think you've defined the macro blah explicitly in your MWE... :-) –  Mico Oct 5 '11 at 14:02
    
\newcommand{\blah}{blah blah blah blah blah blah blah blah} –  egreg Oct 5 '11 at 14:34
add comment

Vertical alignment is possible using makecell. It's contents looks like a mini-tabular with \\ to break lines as necessary. And, it "plays nice" with booktabs:

\documentclass{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{makecell}% http://ctan.org/pkg/makecell
\newcommand{\bla}{%
  \makecell[r]{blah blah\\blah blah blah\\\midrule blah blah\\blah blah}%
}
\begin{document}
\begin{table}[ht]
  \centering
  \begin{tabular}{p{20mm}p{20mm}c} \toprule
    Type   & Specs   & Uses \\ \midrule
    --     & Model 1 & \bla \\ \cmidrule{1-3}
           & Model 2 & \bla \\ \cmidrule{2-3}
    Spring & Model 3 & \bla \\ \cmidrule{2-3}
           & Model 4 & \bla \\ \bottomrule
  \end{tabular}
\end{table}
\end{document} 

makecell

share|improve this answer
    
Werner -- booktabs and makecell might not be playing so nice with each other after all: The four midrules (inside the "blah" macro texts) appear to be "trimmed" both left and right even though you did not specify this behavior in the code. One might be able to address this issue, in the short run at least, by inserting @{} after c in the tabular specification. –  Mico Oct 5 '11 at 16:18
    
@Mico: This is the expected behaviour in my opinion. I was merely illustrating the vertical alignment with respect to the other tabular entries. Throwing in the \midline was to show the tabular-ish \makecell interaction. –  Werner Oct 5 '11 at 16:20
    
I didn't claim this behavior was an outright bug. My point is, rather, that if the horizontal lines don't all terminate at the same "meridian" (vertical line...), the table's appearance may be unnecessarily rough. –  Mico Oct 5 '11 at 16:32
add comment

This is typical case where the \valign instead \halign primitive have to be used. The \valign is transposed primitive to the common used \halign. It means that data are inserted primary to the columns and separated by \cr, then these columns are composed alongside. Each data item becomes the maximal height of its row. The width of each data item is set as a constant in this example.

LaTeX table-like packages use \halign primitive. I don't know if the
\valign is used in some package because I don't know all the LaTeX
packages.

Nevertheless, I am able to show how the \valign works at the TeX primitive level. Sorry, it is not LaTeX.

\def\setrowparams{\hsize=25mm \leftskip=.5em \rightskip=\leftskip
   \emergencystretch=2em \noindent\hfil}

\def\blah{blah blah blah blah blah blah blah blah}
\def\blahh{\blah\ \blah\ \blah\  blah blah blah}

\def\multirow#1#2{\multispan{#1}\hrule\vfil\vbox{\setrowparams\topstrut#2\botstrut}\vfil}

\def\topstrut{\vbox to3ex{}} \def\botstrut{\vtop to2ex{}}

\vbox{\hbox{\vrule
   \valign{&\hrule\vfil\vbox{\setrowparams\topstrut#\unskip\botstrut}\vfil\cr
   Type   & & \multirow3{spring} \cr \noalign{\vrule}
   Specs  & Model 1 & Model 2 & Model 3 & Model 4 \cr \noalign{\vrule}
   Uses   & \hfilneg\blah & \hfilneg\blahh  & \hfilneg\blah &
   \hfilneg\blah \cr 
  \noalign{\vrule}   
}}\hrule}

\end

Now the word "spring" is verticaly centered at every circumstances of the filling the last colum by blah blah...

valign output

How can be this done by LaTeX? The answer "surround my code by LaTeX preamble and postamble" is not accepted.

share|improve this answer
add comment

As a person encountering a similar problem years after this question was last active, it seems that most of the answers here are suggesting things that are helpful in this case but not in general.

After searching through many other questions, I found this one [Vertical Alignment in multirow using cells with >1 lines ] to be the most helpful. Unfortunately the answer is basically "multirow just doesn't do this on its own, but you can tweak it case-by-case."

My own observations from playing with this are that multirow won't account for extra space between lines due to \addlinespace (I believe that booktabs adds extra vertical space around \midrule and \cmidrule, so multirow would be thrown off by these) and behaves as though all of the rows that it spans (except the first) are a single line (i.e. if the second or later row spans more than one line, the vertical spacing will be messed up).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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