Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

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.
by

1 Answer

pankajshivnani123
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}}

Login / Signup to Answer the Question.