# Putting Line Breaks in a table

I have the following latex code:

%\usepackage{multirow}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{Position}                                      & \multirow{2}{*}{CF ($t=0$)}                               & \multicolumn{4}{c|}{CF ( $t=T$ )}                                                                                                                                         \\ \cline{3-6}
&                                                           & $S_T \le 40$                                                       & $40<S_T \le 50$                                                    & $50<S_T \le 70$ & $S_T \ ge 70$ \\ \hline
\begin{tabular}[c]{@{}c@{}}Long 2 Puts  (K=40)\end{tabular}  & \begin{tabular}[c]{@{}c@{}}$-2(10) = -20$\end{tabular} & \begin{tabular}[c]{@{}c@{}}$2(40-S_T) = 80 - 2S_T$\end{tabular} & $0$                                                                & $0$             & $0$           \\ \hline
\begin{tabular}[c]{@{}c@{}}Long Put  (K=70)\end{tabular}     & $-30$                                                     & $70-S_T$                                                           & $70-S_T$                                                           & $70-S_T$        & $0$           \\ \hline
\begin{tabular}[c]{@{}c@{}}Short 3 Puts  (K=50)\end{tabular} & \begin{tabular}[c]{@{}c@{}}$+3(20) =60$\end{tabular}    & \begin{tabular}[c]{@{}c@{}}$-3(50 - S_T)=3S_T-150$\end{tabular} & \begin{tabular}[c]{@{}c@{}}$-3(50 - S_T) =3S_T-150$\end{tabular} & $0$             & $0$           \\ \hline
\textbf{Total}                                                 & $10$                                                      & $0$                                                                & $2S_T-80$                                                          & $70-S_T$        & $0$           \\ \hline
\end{tabular}


Which is the table I want, and this works, but its too wide to fit into my document, so I am just trying to simply put in a line break \\ in some of the cells, for example, same code:

\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{Position}                                      & \multirow{2}{*}{CF ($t=0$)}                               & \multicolumn{4}{c|}{CF ( $t=T$ )}                                                                                                                                         \\ \cline{3-6}
&                                                           & $S_T \le 40$                                                       & $40<S_T \le 50$                                                    & $50<S_T \le 70$ & $S_T \ ge 70$ \\ \hline
\begin{tabular}[c]{@{}c@{}}Long 2 Puts  (K=40)\end{tabular}  & \begin{tabular}[c]{@{}c@{}}$-2(10) = -20$\end{tabular} & \begin{tabular}[c]{@{}c@{}}$2(40-S_T) = 80 - 2S_T$\end{tabular} & $0$                                                                & $0$             & $0$           \\ \hline
\begin{tabular}[c]{@{}c@{}}Long Put  (K=70)\end{tabular}     & $-30$                                                     & $70-S_T$                                                           & $70-S_T$                                                           & $70-S_T$        & $0$           \\ \hline
\begin{tabular}[c]{@{}c@{}}Short 3 Puts  \\(K=50)\end{tabular} & \begin{tabular}[c]{@{}c@{}}$+3(20) =60$\end{tabular}    & \begin{tabular}[c]{@{}c@{}}$-3(50 - S_T)=3S_T-150$\end{tabular} & \begin{tabular}[c]{@{}c@{}}$-3(50 - S_T) =3S_T-150$\end{tabular} & $0$             & $0$           \\ \hline
\textbf{Total}                                                 & $10$                                                      & $0$                                                                & $2S_T-80$                                                          & $70-S_T$        & $0$           \\ \hline
\end{tabular}


Except I placed a \\ infront of the (K=50) and the code no longer works. How can i fix this?

• This does not work in this way. You have to use \makecell and it's \thead facilities.
– user31729
Commented May 4, 2015 at 15:25
• @Christian Hupfer: I suppose you mean the makecell package, not the \makecell command. Commented May 4, 2015 at 18:21
• @Bernard: Yes, the package, sorry, I was too fast
– user31729
Commented May 4, 2015 at 18:23

A solution with makecell:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe]{geometry}
\usepackage{mathtools}
\usepackage{amsfonts}
\usepackage{xcolor}
\usepackage{array, multirow, makecell}
\setcellgapes{4pt}

\begin{document}

\centering\makegapedcells\setlength\tabcolsep{5pt}
\begin{tabular}{|c|*{5}{>{$}c<{$}|}}
\hline
\multirowcell{2}[-1ex]{Position} & \multirowcell{2}[-1ex]{CF ($t=0$)} & \multicolumn{4}{c|}{CF ( $t=T$ )} \\ \cline{3-6}
& & S_T ≤ 40 & 40<S_T ≤ 50 & 50<S_T ≤ 70 & S_T ≥ 70 \\
\hline
\makecell{Long 2 Puts \\ (K=40)} & -2(10) = -20 & \begin{matrix*}[r]2(40-S_T)\quad{}\\= 80 - 2S_T\end{matrix*} & 0 & 0 & 0 \\
\hline
\makecell{Long Put \\ (K=70)} & -30 & 70-S_T & 70-S_T & 70-S_T & 0 \\
\hline
\makecell{Short 3 Puts \\ (K=50)} & +3(20) =60 & \begin{matrix*}[r]-3(50 - S_T)\quad {}\\=3S_T-150\end{matrix*} & \begin{matrix*}[r]-3(50 - S_T)\quad {}\\ =3S_T-150\end{matrix*} & 0 & 0 \\
\hline
\textbf{Total} & 10 & 0 & 2S_T-80 & 70-S_T & 0 \\
\hline
\end{tabular}

\end{document}


• In my point of view the line breaking of the 'equations' (say conditions) is rather confusing
– user31729
Commented May 4, 2015 at 19:49
• Do you mean in the first column? For in the third and fourth columns, I just put the result of a computation on a separate line. Commented May 4, 2015 at 20:00
• Nope, I mean the 'equations' in the 3rd and 4th column.
– user31729
Commented May 4, 2015 at 20:01
• Isn't apparent the second line in the cells are the simplification of the first line? Commented May 4, 2015 at 20:15
• It is, but's not aligned as one would 'expect' from such a continued expression. Never mind (+1) anyway (half an hour ago, already ;-))
– user31729
Commented May 4, 2015 at 20:16

I always consider reformatting tables that go too wide, especially when they're short. To me, that's an indication that the table needs to be rotated by 90 degrees:

\documentclass{article}
\usepackage{booktabs}

\usepackage{multirow}

\begin{document}

\newcommand{\st}{\ensuremath{S_T}}

\begin{table}
\centering
\begin{tabular}{cccccc} \toprule
& & \multicolumn{3}{c}{$K$} \\ \cmidrule{3-5}
Position & & 40 & 70 & 50 & Total \\ \midrule
CF ($t=0$) & & -20 & -30 & 60 & 10 \\ \addlinespace
\multirow{4}{*}{CF ($t=T$)} & $\st \le 40$ & $80-2 \st$ &  $70-\st$ & $3 \st - 150$ & 0 \\
& $40 < \st \le 50$ & 0 & $70-\st$ & $3 \st - 150$ & $2 \st - 80$ \\
& $50 < \st \le 70$ & 0 & $70-\st$ & 0 & $70-\st$\\
& $\st \ge 70$ & 0 & 0 & 0 & 0 \\ \bottomrule
\end{tabular}
\end{table}

\end{document}