Graphics, Figures & Tableswrapping text in multirow cell

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
teperosombrero
Posts: 3
Joined: Tue Feb 23, 2010 8:33 pm

wrapping text in multirow cell

Post by teperosombrero »

Hi,
I'm trying to make a table with horizontally and vertically centered text, moreover, some cells are made by multirow and contain long text to wrap. I used parameter m{width} to wrap a text inside a cell, but it doesn't work in the multirow cell. Any suggestions?
Thank you

Code: Select all

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

\begin{document}
\begin{tabular}{|m{2cm}|c|c|m{2cm}|c|c|}
\hline
\multirow{ 2}{*}{wrap} & \multicolumn{ 2}{c|}{bla bla} & \multirow{ 2}{*}{Long text to wrap} & \multicolumn{ 2}{c|}{bla bla bla} \\
\hhline{~--~--}
 & bla &   bla &  & bla & bla \\
\hline
 a &a &a &a &a &a  \\
\hline
a &a &a &a &ad &a  \\
\hline
\end{tabular}
\end{document}
Last edited by teperosombrero on Wed Mar 17, 2010 12:30 pm, edited 3 times in total.

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

wrapping text in multirow cell

Post by frabjous »

Well, obviously, if you want that text wrapped, you should actually fill in the width field for \multirow, rather than using "*", which tells it to use the full width of the text.

Code: Select all

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

\begin{document}
\begin{tabular}{|m{2cm}|c|c|m{2cm}|c|c|}
\hline
\multirow{2}{2cm}{Long text to wrap} & \multicolumn{2}{c|}{bla bla} & \multirow{2}{2cm}{Long text to wrap} & \multicolumn{ 2}{c|}{bla bla bla} \\
\hhline{~--~--}
 & bla &   bla &  & bla & bla \\
\hline
 a &a &a &a &a &a  \\
\hline
a &a &a &a &a &a  \\
\hline
\end{tabular}
\end{document}
BTW, for short sample code like this, you can use

Code: Select all

...
tags, rather than an attachment.
teperosombrero
Posts: 3
Joined: Tue Feb 23, 2010 8:33 pm

wrapping text in multirow cell

Post by teperosombrero »

OK, the text is wrapped, but I also need it to be aligned in the middle (vertically + horizontally, in the whole column) -this is why I asked, the m{2cm} tag doesn't center the text...
Now I've found out, that

Code: Select all

\multirow{2}{2cm}{\begin{center}Long text to wrap\end{center}}
centers the the text, but the vertical alignment is so bad and the only possibility I know to raise it (\raisebox) seems not to work together with the \begin{center} tag
Post Reply