58

I have a table with many multirow environment that are each compouned with many lines. I have seen that it is possible to break lines in multirows by fixing a particular width (with minipage for example) but I would like to decide where to break a line precisely (with a \newline for instance).

Example of current latex document :

\documentclass{article}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage{multirow}

\begin{document}
\begin{table}
\begin{tabular}{|c|c|}\hline
\multirow{5}{*}{Numbers from 1 to 5}&1 \\ 
&2 \\
&3 \\
&4 \\
&5 \\ \hline
\end{tabular}
\end{table} 
\end{document}

The result is

enter image description here

What i would like to get is something like that :

enter image description here

1

3 Answers 3

59

There is several ways to do it. A very simple way is using \shortstack

\documentclass{article}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage{multirow}

\begin{document}
\begin{table}
  \begin{tabular}{|c|c|}\hline
    \multirow{5}{*}{\shortstack[l]{Numbers from\\ 1 to 5}}&1 \\ 
                                                          &2 \\
                                                          &3 \\
                                                          &4 \\
                                                          &5 \\ \hline
  \end{tabular}
\end{table} 

\begin{table}
  \begin{tabular}{|c|c|}\hline
    \multirow{5}{*}{\shortstack{Numbers from\\ 1 to 5}}&1 \\ 
                                                       &2 \\
                                                       &3 \\
                                                       &4 \\
                                                       &5 \\ \hline
  \end{tabular}
\end{table} 

\begin{table}
  \begin{tabular}{|c|c|}\hline
    \multirow{5}{*}{\parbox{3cm}{Numbers from\\ 1 to 5}}&1 \\ 
                                                        &2 \\
                                                        &3 \\
                                                        &4 \\
                                                        &5 \\ \hline
  \end{tabular}
\end{table}

\end{document}

enter image description here

4
  • 1
    I 'll go with the shortstack, thank you sir !
    – Soji
    Sep 28, 2016 at 9:29
  • Why not nesting a tabular? It would be more flexible.
    – egreg
    Sep 28, 2016 at 9:45
  • 2
    For some reason shortstack produces inconsistent spacing when used in multiple cells next to each other, the makecell solution by Bernard handles this much better. Aug 25, 2017 at 17:48
  • 1
    Parbox works best for me, especially you can also center the text using \centering. Thank you!
    – Mackie
    May 25, 2019 at 14:20
34

Simple with makecell, which is done for this sort of things: use the \multirowcell command (syntax even simpler than \multirow):

\documentclass{article}
\usepackage[frenchb]{babel}
\usepackage[T1]{fontenc}
\usepackage{multirow, makecell}

\begin{document}

\begin{table}
\begin{tabular}{|c|c|}\hline
\multirowcell{5}{Numbers\\from\\ 1 to 5}&1 \\
&2 \\
&3 \\
&4 \\
&5 \\ \hline
\end{tabular}
\end{table}
\end{document} 

enter image description here

-1

A simple option is to use the option to put a size to the column. Replace the c by p{5cm} with the size between the brackets.

1
  • 1
    It could work but I don't want to split my lines at different width in the same column. In reality I am displaying mathematical formulas and for the global understanding , it is better to choose where to cut the formula.
    – Soji
    Sep 28, 2016 at 9:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .