Graphics, Figures & Tablesmultirow | Center multi-line Cell Contents

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
limp
Posts: 2
Joined: Tue Jul 24, 2012 1:54 pm

multirow | Center multi-line Cell Contents

Post by limp »

Hi all,

I encounter a problem when trying to center some text (horizontally and vertically) when using the multirow package.

I used the m{‹width›} parameter to center the text inside the multi-line cell (which contains the "mpla mpla mpla" text), but it doesn't do the work for me.

Any help will be much appreciated.

Code: Select all

\documentclass{article}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{tabularx}

\begin{document}
\centering
\begin{tabular}{| >{\centering}m{1cm} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.6in} | >{\centering}m{0.6in} | >{\centering}m{0.6in}| >{\centering}m{0.6in} |}
\hline
\multirow{2}{1cm}{\centering mpla mpla mpla}& \multicolumn{3}{c|}{Section A} & \multicolumn{4}{c|}{Section B}\tabularnewline\cline{2-8}
   & \bfseries {Cache} & \bfseries {text text text} & \bfseries {text text} & \bfseries {text text text text} & \bfseries {text text} & \bfseries {text text text text text text} & \bfseries {text text}\tabularnewline\hline
\end{tabular}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

multirow | Center multi-line Cell Contents

Post by cgnieder »

\multirow needs to know how large the multiple rows are together. The documentation shows for example an approach where you add a \bigstrut to every line that corresponds to a line of the \multirow and you tell \mutlirow the numbers of \bigstruts in the first optional argument. And then there's of course manual tweeking with the second optional argument. Below I show an example of the latter.

The syntax:

Code: Select all

\multirow{<nrows>}[<bigstruts>]{<width>}[<fixup>]{<text>}
One possibility

Code: Select all

\documentclass{article}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{tabularx}

\begin{document}
\centering
\begin{tabular}{| >{\centering}m{1cm} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.6in} | >{\centering}m{0.6in} | >{\centering}m{0.6in}| >{\centering}m{0.6in} |}
\hline
\multirow{2}{1cm}[-3.5em]{\centering mpla mpla mpla}& \multicolumn{3}{c|}{Section A} & \multicolumn{4}{c|}{Section B}\tabularnewline\cline{2-8}
   & \bfseries {Cache} & \bfseries {text text text} & \bfseries {text text} & \bfseries {text text text text} & \bfseries {text text} & \bfseries {text text text text text text} & \bfseries {text text}\tabularnewline\hline
\end{tabular}
\end{document}
Regards
site moderator & package author
limp
Posts: 2
Joined: Tue Jul 24, 2012 1:54 pm

multirow | Center multi-line Cell Contents

Post by limp »

Thanks for the help,

It will be much better if I could use the \bigstrut command instead of manually adjusting it the height. I read the relevant documentation for using it but I didn't manage to get it work. Here is what I've tried:

Code: Select all

\documentclass{article}
\usepackage{hhline}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{bigstrut}

\begin{document}
\centering
\begin{tabular}{| >{\centering}m{1cm} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.4in} | >{\centering}m{0.6in} | >{\centering}m{0.6in} | >{\centering}m{0.6in}| >{\centering}m{0.6in} |}
\hline
\multirow{2}[2]{1cm}{\centering mpla mpla mpla}& \multicolumn{3}{c|}{Section A} & \multicolumn{4}{c|}{Section B} \bigstrut[t] \tabularnewline \cline{2-8}
   & \bfseries {Cache} & \bfseries {text text text} & \bfseries {text text} & \bfseries {text text text text} & \bfseries {text text} & \bfseries {text text text text text text} & \bfseries {text text} \bigstrut[b] \tabularnewline \hline
\end{tabular}
\end{document}
Could someone please point me out what I am doing wrong?
Also, the "-3.5em" value that you used is after trial and error or there is some logic behind it (a calculation that you did)?

Thanks again.
Post Reply