90

Possible Duplicate:
How to add a forced line break inside a table cell

In a table I would like to have a line break in the text inside a cell. Is there an easy way to do so, or do I have to create a new line without borders? The same holds true for other situations such as breaking a line in a caption for instance.

5
  • 4
    It took me a while to understand the problem, it might be worth stating that simply using a \\ in the text created a new line for all columns and this (presumably) is what you are trying to avoid. Commented Jul 29, 2010 at 0:04
  • 1
    You can also use a minipage inside your table (it's similar to a parbox).
    – Rebekah
    Commented Jul 29, 2010 at 3:42
  • @Yossi: exactly, using \\ acts weird in a table, and has no effect in a caption. I think there are many cases where you can't use \\ but stil would like to break line. In a figure / box e.g.
    – damusnet
    Commented Jul 29, 2010 at 19:11
  • 1
    See also How to add a forced line break inside a table cell. Commented Jul 26, 2011 at 5:29
  • You might want to use varwidth which provides a minipage with variable width (e,g, just as much width as needed for the content) in which you can break lines
    – Jaleks
    Commented Feb 2, 2020 at 18:21

5 Answers 5

74

Would a \parbox work?

\begin{tabular}{ll}
one line& \parbox[t]{5cm}{another\\column}\\
second line here& and here
\end{tabular}
4
  • 2
    Is it possible to make parbox tight and omitting the width parameter somehow? And how to make it centered?
    – nimcap
    Commented Dec 20, 2011 at 15:31
  • @nimcap: better to start a new question than put it here...What do you mean by tight? a table is flexible and its width depends on the width of its contents? center by centering the column of the table (using c) and centering the parbox, using \begin{center}.... Commented Dec 22, 2011 at 2:23
  • 1
    @YossiFarjoun: I started a new question here: tex.stackexchange.com/questions/38924/…
    – nimcap
    Commented Dec 22, 2011 at 8:44
  • 1
    @nimcap: and arn't you glad you did? ;-) Commented Dec 22, 2011 at 17:27
52

\newline works in paragraph columns

Example:

\begin{tabular}{|p{3cm}|p{3cm}|}
first line
\newline second line & still on first line \\
\end{tabular}
0
15

Is this for a single cell, or an entire column of cells? If the later, try:

\documentclass{article}
\begin{document}
    \begin{tabular}{lp{.2\textwidth}l}
        42 & A paragraph of text & 42\\
        42 & Another paragraph & 42
    \end{tabular}
\end{document}

Even if it is for a single cell, I suspect that this is still the way to go.

5

Regarding line breaks in captions: if you use the caption package \\ works. In the optional argument you should protect it. Here's a demonstration example:

\documentclass{article}
\usepackage[font=small,labelfont=bf]{caption}
\begin{document}
\listoffigures
\bigskip
\begin{figure}[hb]
\centering Test
\caption[Short\protect\\text]{Test\\example}
\end{figure}
\end{document}

Because the caption package provides a lot of features regarding justification and customization I would not work without it. But if you really wish to avoid this package, it can also be done using \parbox. The optional positioning parameter t might be useful:

\documentclass{article}
\begin{document}
\listoffigures
\bigskip
\begin{figure}[hb]
\centering Test
\caption[Short\protect\\text]{\parbox[t]{0.2\textwidth}{Just a Test\\example}}
\end{figure}
\end{document}
1
  • 1
    Thanks for your fine code! I had an awful error in the subfigure environment, but your idea of using ` \protect\\ ` instead of ` \\ ` has fixed it. (I had given ` \\ ` as a macro parameter and it did not work). Commented Oct 15, 2015 at 14:19
5
\usepackage{pbox}

\begin{tabular}{|l|l|} \hline
    \pbox{20cm}{This is the first \\ cell} & second \\ \hline
    3rd & and the last cell \\ \hline
\end{tabular}
1

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