Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Centering Text within a Multirow Cell in LaTex

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.

like image 976
Paul Avatar asked Dec 15 '09 21:12

Paul


3 Answers

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.

like image 181
DMI Avatar answered Oct 23 '22 12:10

DMI


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.

like image 15
Harish Avatar answered Oct 23 '22 11:10

Harish


\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.

like image 5
user1189728 Avatar answered Oct 23 '22 11:10

user1189728