Skip to main content

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Asked
Modified 9 years ago
Viewed 64k times
65

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

67

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

3
  • Why not nesting a tabular? It would be more flexible.
    egreg
    –  egreg
    2016-09-28 09:45:01 +00:00
    Commented Sep 28, 2016 at 9:45
  • 3
    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.
    Maarten Derickx
    –  Maarten Derickx
    2017-08-25 17:48:36 +00:00
    Commented Aug 25, 2017 at 17:48
  • 1
    Parbox works best for me, especially you can also center the text using \centering. Thank you!
    Mackie
    –  Mackie
    2019-05-25 14:20:32 +00:00
    Commented May 25, 2019 at 14:20
39

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
  • 2
    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
    –  Soji
    2016-09-28 09:23:57 +00:00
    Commented Sep 28, 2016 at 9:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.