One element of a multirow column is long. How can I split it so that it spans over multiple line. The following code
\documentclass{article}
\usepackage{multirow,array}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{rcc}
\toprule
Name & Subject & Grade \\
\midrule
\multirow{3}*{John} & Maths & A \\
& Science & A \\
& Arts & A \\[.5\normalbaselineskip]
\multirow{3}*{Very Long Name} & Maths & A \\
& Science & A \\
& Arts & A \\
\bottomrule
\end{tabular}
\end{document}
generates:
Is there a way to split the "Very Long Name" into multiple row?
Best Answer
What you might like to do is to use a
minipage
, within the\multirow
argument to force the name to a certain horizontal width, breaking it across multiple lines if it exceeds a certain width. (This requires names with enough spaces, or at least which are allowed to be hyphenated.)As
egreg
suggests in the comments, if you do not want the "Name" column to always take up the maximum possible width if the names are all sufficiently short, better still would be to use avarwidth
environment (using thevarwidth
package), which also allows the text to take up less than the maximum amount of horizontal space.Sample code:
(You should edit the width of the varwidth/minipage environment to suit your needs.)
Output: