26

This is probably best explained with an example. I have the following table, where the "A" cell spans two rows, and the "B" cell spans two columns.

\begin{table}[htdp]
\begin{tabular}{l|r|r}
\multirow{2}{*}{A} & \multicolumn{2}{c}{B} \\
  & B1 & B2 \\
a & b1 & b2 \\
a & b1 & b2 \\
\end{tabular}
\end{table}
 _ _ _ _ _ _ _ _ _ _ _ _ 
|A      |_ _ _ _B_ _ _ _|
|_ _ _ _|_ _B1_ |_ _B2_ |
|a      |     b1|     b2|
|a      |     b1|     b2|
|a      |     b1|     b2|
|_ _ _ _| _ _ _ |_ _ _ _|

I would like to center the text in the "A" cell, only. I would like to leave the rest of the column left-aligned. Giving:

 _ _ _ _ _ _ _ _ _ _ _ _ 
|   A   |_ _ _ _B_ _ _ _|
|_ _ _ _|_ _B1_ |_ _B2_ |
|a      |     b1|     b2|
|a      |     b1|     b2|
|a      |     b1|     b2|
|_ _ _ _| _ _ _ |_ _ _ _|

I'm sure this must be simple to do, but I can't seem to put my finger on it.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Paul
  • 16,285
  • 13
  • 41
  • 52
  • Thanks for a clear example of what you wanted to accomplish, by the way! – DMI Dec 15 '09 at 21:26
  • Thanks, Dave :-) I was wondering whether I might be stating the obvious a little with the second table, but I felt one can't make things too clear. – Paul Dec 15 '09 at 21:35

4 Answers4

18

I think you need to do that with a fake \multicolumn:

\multicolumn{1}{c}{\multirow{2}{*}{A}} & \multicolumn{2}{c}B} \\

Inspiration from this FAQ.

DMI
  • 6,843
  • 2
  • 24
  • 25
  • 1
    That gives: ! Misplaced \omit. \multispan -> \omit \@multispan. Not sure what that means :-S – Paul Dec 15 '09 at 21:29
  • Try swapping the nesting of the multirow/multicolumn? (so the multicolumn is on the outside). Sorry, I haven't got a working LaTeX install here to play with! – DMI Dec 15 '09 at 21:38
  • Edited answer to put multirow inside multicolumn instead of the other way round -- sorry, I think I got the nesting backwards! – DMI Dec 15 '09 at 21:45
16

I came across a similar problem, but had to use \multirow{specified width}{} instead of \multirow{*}{}. Nesting multirow inside a multicolumn does not work in this case.

I found \multirow{specified width}{\centering text} to work instead.

jevon
  • 3,197
  • 3
  • 32
  • 40
Harish
  • 161
  • 1
  • 2
  • This works particularly well if you are trying to center-align text over multiple rows, whereas the other solution only aligns the entire block. Thanks :) – jevon May 25 '11 at 04:22
  • I think you have the arguments in the wrong order. nrows is before width, right? – lindhe Dec 30 '15 at 11:54
7
\multirow{2}{*}{\hfil A}

\hfil will automatically calculate the width of the cell and insert a half-width space

To insert a full cell-width space, which will right-justify a single cell, use \hfill. There are also \vfil and \vfill analogues.

user1189728
  • 157
  • 1
  • 4
  • 8
1

That is could be helpful for someone

\begin{tabular}{|c c | c|c|c|}
\hline
\multicolumn{2}{|c}{\multirow{2}{*}{Modulation}} & \multicolumn{3}{|c|}{M} \\
\cline{3-5}
&  & 2  & 4 & 8 \\
\hline
   \multirow{3}*{\hfil SNR=$\begin{cases}  \\  \\  \end{cases}$}    &  STMA &  xx dB & xx dB & xx dB\\
      &  QTMA    & xx dB & xx dB & xx dB \\
      &  POSTMA & xx dB & xx dB & xx dB\\
\hline
\end{tabular}