Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

marked as duplicate by Stefan Kottwitz Jan 24 '12 at 23:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
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. –  Yossi Farjoun Jul 29 '10 at 0:04
    
You can also use a minipage inside your table (it's similar to a parbox). –  Rebekah Jul 29 '10 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. –  Damien Jul 29 '10 at 19:11
1  

5 Answers 5

up vote 36 down vote accepted

Would a \parbox work?

\begin{tabular}{ll}
one line& \parbox[t]{5cm}{another\\column}\\
second line here& and here
\end{tabular}
share|improve this answer
    
like a charm, thx! –  Damien Jul 28 '10 at 17:00
    
Is it possible to make parbox tight and omitting the width parameter somehow? And how to make it centered? –  nimcap Dec 20 '11 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}.... –  Yossi Farjoun Dec 22 '11 at 2:23
    
@YossiFarjoun: I started a new question here: tex.stackexchange.com/questions/38924/… –  nimcap Dec 22 '11 at 8:44
1  
@nimcap: and arn't you glad you did? ;-) –  Yossi Farjoun Dec 22 '11 at 17:27

\newline works in paragraph columns

Example:

\begin{tabular}{|p{3cm}|p{3cm}|}
first line
\newline second line & still on first line \\
\end{tabular}
share|improve this answer

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.

share|improve this answer

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}
share|improve this answer
\usepackage{pbox}

\begin{tabular}{|l|l|} \hline
    \pbox{20cm}{This is the first \\ cell} & second \\ \hline
    3rd & and the last cell \\ \hline
\end{tabular}
share|improve this answer
2  
Thanks for the code example. Generally, it would be great to add some explanation to code in answers. In this special case, the reader can find some words here: How to add a forced line break inside a table cell. –  Stefan Kottwitz Feb 26 '11 at 14:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.