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

Soji
  • 705
  • http://tex.stackexchange.com/questions/2441/how-to-add-a-forced-line-break-inside-a-table-cell – Zam Sep 28 '16 at 09:22

3 Answers3

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

flav
  • 4,714
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

Bernard
  • 271,350
-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.

AlexDC
  • 161
  • 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 '16 at 09:23