# How to add a forced line break inside a table cell

I have some text in a table and I want to add a forced line break. I want to insert a forced line break without having to specify the column width, i.e. something like the following:

\begin{tabular}{|c|c|c|}
\hline
Foo bar & Foo <forced line break here> bar & Foo bar \\
\hline
\end{tabular}


I know that \\ inserts a line break in most cases, but here it starts a new table row instead.

A similar question was asked before: How to break a line in a table

Strangely, no answer (unless I've misread them) mentions a package that is dedicated to this precise question: makecell, which allows for common formatting of certain cells, thanks to its \thead and \makecell commands, and for line breaks inside these cells. The horizontal and vertical alignments can chosen independently from those of the table they're included in. The default is cc, but you can change it globally in the preamble with

\renewcommand{\cellalign/theadalign}{vh}


where v is one of t,c,b and h one of l,c,r. Alternatively, for a single cell, you can use the \makecell or \thead commands with the optional argument [vh].

So here is a demo:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{array}
\usepackage{makecell}

\renewcommand\cellgape{\Gape[4pt]}

\begin{document}

\begin{center}
\begin{tabular}{ | c | c | c |}
\hline
\hline
Some text &  \makecell{Some really \\ longer text}  & Text text text  \\
\hline
\end{tabular}
\end{center}

\end{document}


• This is certainly the best answer! – kjetil b halvorsen Nov 27 '14 at 12:35
• This is great, it works without specifying a width and does not need confusing hacks. Maybe worth to mention that the example here contains much more than is actually necessary to answer the question: just adding \usepackage{makecell} and using \makecell{...\\...} is sufficient to get a linebreak in the cell. – luator May 11 '15 at 9:48
• It makes me happy to have contributed the 100th upvote. – Mico Apr 3 '17 at 17:21
• This answer is satisfying to read. Psychotherapy has to consider it. – Diaa Apr 17 '17 at 20:29
• As explained, if it's for all you document, \renewcommand{\cellalign}{l} (it will remain vertically centred), or, for some specific cells, makecell[l]{ ... } or \thead[l]{ ... }. – Bernard Feb 26 '18 at 13:04

It's a quite old question, but I'll add my answer anyway, as the method I suggest didn't appear in the others

\begin{tabular}{|c|c|c|}
\hline
Foo bar & \begin{tabular}[x]{@{}c@{}}Foo\\bar\end{tabular} & Foo bar \\
\hline
\end{tabular}


where x is either t, c, or b to force the desired vertical alignment.

In case this is needed in more than a couple of places, it's better to define a command

\newcommand{\specialcell}[2][c]{%
\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}


so the table line before can be one of

Foo bar & \specialcell{Foo\\bar} & Foo bar \\    % vertically centered
Foo bar & \specialcell[t]{Foo\\bar} & Foo bar \\ % aligned with top rule
Foo bar & \specialcell[b]{Foo\\bar} & Foo bar \\ % aligned with bottom rule


More variations are possible, for instance specifying also the horizontal alignment in the special cell.

Notice the @{} to suppress added space before and after the cell text.

• For those wanting to control the horizontal alignment, change c@ to l@ or r@ (or make it another parameter like the vertical alignment?). Thanks egreg – Dolan Antenucci Apr 19 '12 at 13:31
• \parbox will do the same, but you have set a width: \parbox[t]{5cm}{foo\\bar} – Born2Smile Dec 8 '12 at 14:11
• @Born2Smile There's the varwidth environment (package of the same name), but it's overkill. – egreg Dec 8 '12 at 14:15
• This wins the prize for the most incomprehensible answer. – Ricky Robinson Jan 13 '14 at 13:00
• Egreg's solution is one of the most interesting and efficient I ever seen for line breaking at tables! Thanks. However, I made a slight change to specify the alignment directly from the command \specialcell: \newcommand{\specialcell}[3][c]{% \begin{tabular}[#1]{@{}#2@{}}#3\end{tabular}}% which should be called by \specialcell{<align>}{text1\\text2} where <align> must be replaced by the desired position: l (left), c (center), r (right). Despite this mod, all credits to @egreg. – Carlos Viegas Apr 13 '15 at 0:40

It really is no wonder why LaTeX is said to be complicated! Just look at your answers to such an easy question! How about an easy solution to an every day problem?

\usepackage{pbox}

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


which looks like:

Note that the width supplied to \pbox is a maximum width. If the content is shorter the length of the longest line is taken.

• This may be an obvious question. What is the 20cm for, and is there a way to remove it? (automatically choose the correct value) – AnnanFay Dec 2 '13 at 4:38
• The \pbox solution is great. Alignment might be a bit tricky. If you run into trouble using this solution, see here tex.stackexchange.com/a/55861/13450 – Christian Apr 8 '14 at 17:23
• How to center the new line? – CroCo Sep 19 '14 at 14:22
• Well, it’s still overly complicated because it’s a fixed width, but on the other hand I don’t want to be Mr Complainy Pants. – Lenar Hoyt Dec 18 '14 at 20:00
• I gave a downvote because this answer presented in a condescending way. – dinosaur Feb 11 '17 at 17:51

You can switch your cell layout to paragraph to use the \newline command.

\begin{tabular}{|p{2cm}|p{2cm}|}
\hline
Test & foo \newline bar \\
...


Edit:

Use the following commands instead of p if you want to specify the alignment as well:

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

• I did. I tried both \newline and \linebreak, but they only work in paragraph mode. cims.nyu.edu/cgi-comment/info2html?(latex)%5Cnewline – Denilson Sá Maia Aug 28 '10 at 0:56
• Hmm. I thought it did. I could have sworn I've done this before. The only thing I can think of right now is to put a single column tabular within the other tabular. E.g., Foo bar & \begin{tabular}{c} Foo \\ bar \end{tabular} & foo bar \\ – frabjous Aug 28 '10 at 2:59
• @frabjous: Could you clarify the status of this answer? Does it work, and if so, how? (A complete MWE would be good.) – doncherry Jun 9 '12 at 15:06
• @doncherry: This answer works, iff your column type is p{width} or X (in a tabularx environment). It does not work with c, l or r columns, as requested by the asker, though. – Fritz Aug 28 '12 at 13:11
• @doncherry I added a work around which will allow you to specify the alignment as well. – Matthias Jan 26 '17 at 13:24

Use the tabularx environment instead of tabular, and then use \newline where you want line breaks within a cell.

\usepackage{tabularx}
\begin{tabularx}{\textwidth}{lX}
Section:   &  This is my     \newline
long paragraph \\
\end{tabularx}


The tabularx environment has a special column type, X, in addition to the usual ones, and its first argument is the desired width of the table. The X column will have the necessary width in order to make the whole table the desired width.

Note: \newline will not take effect in columns of standard type.

Details on tabularx can be found here.

• Nice one, I hadn't realised tabularx supported this, thanks for mentioning it. – sharky Feb 23 '12 at 4:02
• By far the easiest solution! – mtsz Oct 9 '12 at 21:33
• How does this work? I'm not getting the desired output. – CroCo Mar 28 '15 at 1:56
• @CroCo, add the \usepackage... line in your main.tex and the rest of the code shown works perfectly. +1 for this answer, which does not only work for \newline but also allows many other commands and even environments \begin{...} ... \end{...}, which was all very forbidden in the normal tabular environment. – Steeven May 1 '15 at 14:35
• @carandraug, note that the question asks specifically for a forced line break, so the explicit \newline is not pointless. – Will Jan 14 '16 at 17:19

Here's a very simple way to do it, using Plain TeX commands within the tabular environment:

\begin{tabular}{|c|c|c|}
\hline
here&\vtop{\hbox{\strut top line}\hbox{\strut botline}}&more\\
\hline
x&y&z\\
\hline
\end{tabular}


By using hboxes within the vtop we've stayed in vertical mode and therefore the width of the text in the hboxes determines the width of the vtop. This way we don't need to know the width of the text in advance. \strut will maintain the right space above and below the text in the hbox.

• Hi Amy, and welcome to TeX.sx. You might want to read Welcome to TeX.SX! and note that signing your posts is not necessary since your name appears at the bottom automatically. See also Rules about linking to external pages. With respect to this particular answer, how is it different from TH's answer? – Alan Munn Sep 10 '13 at 20:08
• Thank you! This works when you are in a multicell but they are left aligned (even through I defined it to be in the centre). Is there a way around this? – user2822693 May 14 '14 at 16:41
• The nice thing about this answer is that \vtop{\hbox{\strut top line}\hbox{\strut botline}} can be used within Pandoc Markdown tables. – Serge Stroobandt Oct 21 '14 at 11:11
• @SergeStroobandt not only that. It can be used everywhere! (because is TeX) I just needed some line break in \text of \alignat environment and worked perfectly. Thanks for this robust and simple answer! – loved.by.Jesus Jan 4 '16 at 11:07
• Definitely the best answer on this page ! – Gabriel Romon Feb 26 '19 at 11:09
\begin{tabular}{lll}
a&\vbox{\hbox{\strut ASDF}\hbox{\strut ASDF}\hbox{\strut This is my
really long line}}&c
\end{tabular}


The \strut is essential for spacing.

• This looks like good method. Maybe too much to ask, but is there any easy way to adjust vertical justification in the cells? E.g., so single line cells are even with top of multi-line cell? Or so all are vertically centered? – Herbert Sitz Aug 28 '10 at 15:33
• Replace \vbox with \vtop to get alignment at the top. – TH. Aug 29 '10 at 0:49
• Great answer. How do you center horizontally? – denilw Oct 21 '10 at 20:47
• @denilw: Oops. I misread and wrote a previous comment (now deleted). If you want to center the lines, the easiest way is to compute the width of the widest \hbox and use that as the width of the other \hboxes. Something like \vbox{\setbox0\hbox{\strut This is the widest one.}\hbox to\wd0{\hss\strut ASDF\hss}\copy0\hbox to\wd0{\hss\strut asdf\hss}} – TH. Oct 21 '10 at 21:05
• Why is "ASDF" used for the strut? – einpoklum Feb 25 '17 at 13:54

You can also just fake it:

\begin{tabular}{|c|c|c|}
\hline
Foo bar & Foo & Foo bar \\
~       & bar &  ~      \\
\hline
\end{tabular}


This is a really old question, but since this was linked from a recent question on separating content and presentation, I'll add a ConTeXt answer for comparision.

In ConTeXt, \crlf adds a forced line-break, so achieving a forced line-break in a table is as simple as just adding \crlf in the appropriate place. Here is the complete example:

% Setup for rules at the top and bottom
\startsetups table:rules
\setupTABLE[frame=off]
\setupTABLE[row][first][topframe=on]
\setupTABLE[row][last][bottomframe=on]
\stopsetups

% Setups for middle alignment
\startsetups table:middle
\setupTABLE[align=middle]
\stopsetups

\starttext

\startTABLE[setups={table:rules, table:middle}]
\NC Foo bar \NC Foo \crlf Bar \NC Foo bar \NC \NR
\NC Foo bar \NC Foo \crlf Bar \NC Foo bar \NC \NR
\stopTABLE

\stoptext


which gives:

• your source code does not match what the illustration shows. – Kurt Pfeifle Nov 17 '13 at 13:28
• @KurtPfeifle: It does for me! Which version of context are you using? – Aditya Nov 17 '13 at 20:34
• Sorry, didn't see your question earlier. My context is v. 0.60 (2013.04.20 01:15). However, now re-testing your code, I can confirm that your code works. I have to withdraw my previous statement. Can't remember now what caused me to make it. – Kurt Pfeifle Feb 11 '14 at 19:30
• As usual, ConTeXt is easiest with its \crlf (carriage return linefeed) command. – Serge Stroobandt Oct 21 '14 at 12:28

Here I use stacks to accomplish it. Several things are noteworthy:

1. I demonstrate \Longstack , \Longunderstack and \Centerstack, which give three different alignments.

2. In order not to squeeze against the vertical margins, a \strutlongstacks{T} declaration was issued. Alternately, one might wrap a stack inside an \addstackgap[<gap>]{content} to add a vertical buffer above/below the stack.

3. Not shown is the ability to set the horizontal alignment of the stacked content with an optional argument, or to change the EOL character (from \\ to another user-specified token)

Here is the MWE.

\documentclass{article}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\strutlongstacks{T}
\begin{tabular}{|c|c|c|}
\hline
Foo bar & \Longstack{ Foo \\ bar \\ baz} & Foo bar \\
\hline
Foo bar & \Longunderstack{ Foo \\ bar \\ baz} & Foo bar \\
\hline
Foo bar & \Centerstack{ Foo \\ bar} & Foo bar \\
\hline
\end{tabular}
\end{document}


• This is gorgeous! I'm wondering why it has so few votes... – CarLaTeX Apr 28 '17 at 7:39
• @CarLaTeX Thanks for the kind words. I think that I give so many answers with stacks, people are of the opinion, "you seen one, you seen 'em all." I am a victim of my own success. – Steven B. Segletes Apr 28 '17 at 9:52
• It's really a pity that people stop at the first answers! :) – CarLaTeX Apr 28 '17 at 10:36

How about using \parbox in a custom command

\documentclass{article}
\newsavebox\mybox
\newlength\mylength
\newcommand\boxup[2]{%
\savebox\mybox{#1}%
\setlength\mylength{\wd\mybox}%
\parbox{\mylength}{#1 \\ #2}%
}
\begin{document}
\begin{tabular}{|c|c|c|}
Foo bar & \boxup{Foo}{bar} & Foo bar \\
\end{tabular}
\end{document}


This takes two arguments with the assumption that the first line is longer than the second. It would be possible to refine the code to work through an arbitrary number of lines and find the longest. If that's of interest I'll write something, probably using expl3 for the looping.

• Gives me issues with too little vertical spacing. \vspace only helps for the bottom margin. – Aleksandr Levchuk Oct 23 '11 at 22:09

I believe I have the simplest answer here:

If you are using a paragraph column in a table, you can put text in an alignment environment and the table does not pick up the \\ as a new table row, so you can use it normally. For example:

\begin{tabular}{p{2in}p{2in}}
\begin{flushleft}
Some text over here \\
newline! \\
\bigskip all the way down
\end{flushleft}
&
\begin{flushleft}
Lorem ipsum dolor sit amet, consectetur
tempor incididunt ut labore et dolore
magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo\\ \bigskip
consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur.
Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia
deserunt mollit anim id est laborum.\\
\bigskip \bigskip lorem ipsum\\
\end{flushleft}\\
\end{tabular}\


Will give you a table with line breaks using the \\ command.

• I think the explanation is wrong - I just tried {flushleft} in a l column, and it fails; I think the reason why this example works is because it has p{2in} column type, which sets the width in advance.. – sdaau Jul 10 '14 at 1:08

I think multirow is a simple elegant solution, at least for simple tables.

For example, I tried a few of the suggestions above but I found this worked the best:

\usepackage{multirow}
\begin{table}[ht]
\caption{RESTful Resources}
\centering
\begin{tabular}{l l l}
\hline
Resource & Methods & Description \\
\hline
\multirow{2}{*}{Resource1} & \multirow{2}{*}{POST, PUT}
& This resource contains ...\\
& & \emph{Media types: text/plain, application/json}\\
\multirow{2}{*}{Resource2} & \multirow{2}{*}{POST, PUT}
& This resource contains ...\\
& & \emph{Media types: text/plain, application/json} \\
\hline
\end{tabular}
\label{table:resources}
\end{table}


I don't have direct help on how to add a linebreak, but using the multirow package may provide different route to same desired end. You can read a tutorial here:

http://andrewjpage.com/index.php?/archives/43-Multirow-and-multicolumn-spanning-with-latex-tables.html

But I have a feeling the \parbox answer in the similar question you linked is what you're looking for. I think using a box in the cell is going to be simplest and best way, was there something about that that wasn't working for you?

If you want to use parbox without having to hardcode in a width, here's one way that works for me. Not perfect, since it requires you to know beforehand the text of the longest line in the multi-line column, but it does work:

% define new length and set to length of longest line
\newlength{\longline}
\settowidth{\longline}{longest line in table}\\

\begin{tabular}{lll}

one line & \parbox[t]{\longline}{longest line in table \\ and another line} & more text \\
second line here& and what & more text
\end{tabular}

• \parbox works, but it requires me to type the desired column width. Thus, I lose the auto-column-size that happens otherwise. I bet \multirow will work, but the source-code will be a lot messy. – Denilson Sá Maia Aug 28 '10 at 1:39
• Gotcha. Added code sample to my question that uses column autosizing with parbox and is probably cleaner than using multirow package. I think there must be a better way, but at least it works. . . – Herbert Sitz Aug 28 '10 at 4:38

Good afternoon, when I was younger I was typesetting a tabular environment inside a tabular environment. Since we have TikZ I use tikzpicture environment inside tabulars, or even tikzpicture inside tikzpicture. I prefer putting simple TikZ nodes next and below each other, but it depends on actual task. I enclose an MWE with fast text height correction.

\documentclass{article}
\usepackage{tikz}\pagestyle{empty}
\begin{document}
\tikzset{inner sep=0pt}
\begin{tabular}{|l|l|} \hline
\begin{tikzpicture}
\node[align=left, text height=4.5ex]{This is the\\[3pt]first cell};
\end{tikzpicture}
& second \\ \hline
3rd & and the last cell \\ \hline
\end{tabular}
\end{document}


• \tikz \node[align=left, text height=4.5ex]{This is the\\[3pt]first cell}; is a more brief variant. – Ali Dec 2 '19 at 22:04

Personally, I prefer to use \usepackage{multirow} \multirow{"number of rows"}{"width"}{"contents"} for everything else except the information that should be on different rows.

For example:

 \begin{tabular}{p{2.5cm}@{\hskip 0mm}  p{5cm}@{\hskip 4mm} p{5cm} }
Parameter & Description & Used by\\
\hline
\\[-0.1cm]
\multirow{2}{*}{Accuracy}&1. The error rate or frequency of correctness of sensor readings.  & \\[0.3cm]
& 2. The degree of correspondence of measured values to actual values.& \\[0.3cm]
\hline
\\[-0.1cm]
\end{tabular}


• This works even without the multirow. – ankhi Apr 11 '18 at 5:37

This approach isn't so different from some of the others already given, except that it "externalises" all of the design decisions from the table definition itself (that is, leaving it cleaner to write and read each table should you want to include multiple tables like this throughout your doc or docs).

\usepackage{array} % needed if you're going to use \\ together with centering,
% raggedright, raggedleft in your column specifier (see
% manuals on \arraybackslash)
\newlength{\mywidestcolwidth}
\newcommand*\mycellformat{\protect\footnotesize}
\newcommand*\mytableparskip{\setlength\parskip{4pt}}
\newcommand*\setmywidestcolwidth[1]{
\settowidth{\mywidestcolwidth}{\mycellformat #1}
}


Usage:

\setmywidestcolwidth{foo baz bar}
\begin{tabular}{|>{\mycellformat}c
|>{\mytableparskip\mycellformat\centering\arraybackslash}p{\mywidestcolwidth}
|>{\mycellformat}c|}
\hline
foo bar baz&
foo

foo baz bar

baz&
foo

foo baz bar

baz\\ \hline
\end{tabular}


Skip the \mycellformat and \parskip if you have no need for them (although not necessary in your case, I included \parskip since it's useful to visually distinguish paragraphs from one another since paragraph indentation is automatically switched off in tables, and added \mycellformat to allow for uniform document-wide table design settings).

You can use minipage:

\begin{minipage}[t]{0.2\columnwidth}%
This is the first line
\newline
second line
\newline
...
\end{minipage}

• You have to specify width in advance, though... – sdaau Jul 10 '14 at 1:06

It seems there is a rather simple solution. Just wrap the text into currly braces and use \raggedright like this:

{\raggedright \bfseries WS 2016 \\(average)}


Here is a simple example:

\begin{tabularx}{\textwidth}[ht]{|X|p{1.8cm}|}
\hline
Some Longer Column &
{\raggedright \bfseries Line \\Break} \\\hline
This is a wide line with some text & Small \\\hline
\end{tabularx}


This gives:

• The only answer which actually works rigtht without messing with my other table cells! – user Apr 11 '19 at 1:23