3

I have a table with some multirow cells. Sometimes the cell content is wider than the cell, the it has to make a breakline. Reading a little, I founded that specifying the multirow width, the text will automatically break, however, after the linebreak, the text stay outside of the cell. How can I solve it?

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\begin{tabular}{c*2{>{\centering\arraybackslash}m{2cm}}}
\cmidrule{2-3}
 & \textbf{Column 1} & \textbf{Column 2}\\
\midrule
 \textbf{Row 1}  & \multirow{2}{*}{A longer text for line break} & Text row 1\\
\cmidrule{1-1}\cmidrule{3-3}
 \textbf{Row 2}  & & Text row 2\\
\midrule
 \textbf{Row 3}  & Text row 3 & A longer text for line break\\
\midrule
\end{tabular}
\end{table}
%
\begin{table}
\centering
\begin{tabular}{c*2{>{\centering\arraybackslash}m{2cm}}}
\cmidrule{2-3}
 & \textbf{Column 1} & \textbf{Column 2}\\
\midrule
 \textbf{Row 1}  & \multirow{2}{2cm}{\centering A longer text for line break} & Text row 1\\
\cmidrule{1-1}\cmidrule{3-3}
 \textbf{Row 2}  & & Text row 2\\
\midrule
 \textbf{Row 3}  & Text row 3 & A longer text for line break\\
\midrule
\end{tabular}
\end{table}
\end{document}

enter image description here

2

The problem is that the multirow cell has 3 lines whereas the corresponding table rows are only two.

I think you could solve the problem increasing the height of those two rows by some struts and some spaces added at the end of them.

By the way, multicol package is used to have two columns of text, it is not necessary to use \multicolumn (from its position in your MWE I think you thought that).

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{rotating}
\usepackage{booktabs}
%\usepackage{multicol}
\usepackage{multirow}
\usepackage{array}
\newcommand{\myrule}{\rule{0pt}{\baselineskip}}
\begin{document}
\begin{table}
\centering
\begin{tabular}{c*2{>{\centering\arraybackslash}m{2cm}}}
\cmidrule{2-3}
 & \textbf{Column 1} & \textbf{Column 2}\\
\midrule
 \myrule\textbf{Row 1}  & \multirow{2}{2cm}{\centering A longer text for line break} & \myrule Text row 1\\[4pt]
\cmidrule{1-1}\cmidrule{3-3}
 \myrule\textbf{Row 2}  & & \myrule Text row 2\\[4pt]
\midrule
 \textbf{Row 3}  & Text row 3 & A longer text for line break\\
\midrule
\end{tabular}
\end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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