# [Tex/LaTex] Split the title of a table into more than one row

spacingtables

Suppose I had the following;

\begin{table}
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{Table1}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -19.0123  \\ \hline
2 & -16.4377 \\ \hline
3 & -13.3349 \\ \hline
4 & -11.7427  \\ \hline
5 & -10.1329 \\ \hline
6  & -9.0075 \\ \hline
7 & -6.0001 \\ \hline
\end{tabular}
\quad
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{table2}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -16.0123  \\ \hline
2 & -12.4377 \\ \hline
3 & -9.5532 \\ \hline
4 & -5.7427  \\ \hline
5 & -4.1329 \\ \hline
6  & -3.0075 \\ \hline
7 & -3.0001 \\ \hline
\end{tabular}
\quad
\begin{tabular}{|c|c|}
\hline
\multicolumn{2}{|c|}{table3}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -5.0123  \\ \hline
2 & -2.4377 \\ \hline
3 & -3.3349 \\ \hline
4 & -1.7427  \\ \hline
5 & -1.1329 \\ \hline
6  & -1.0075 \\ \hline
7 & -1.0001 \\ \hline
\end{tabular}
\end{table}


Notice how the first columns only have small entries (At most they will have 8 figures), I was wondering what I could insert in this to make it so that that the title of column 1 (the long equation with k as input) would split into more than one row – whilst remaining centred.

Thanks – and apologies if this has already been answered,
Rob.

EDIT: The end idea is to ensure all tables are next to one another on the same row.

#### Best Answer

You can load array package and declare a new column type

\newcolumntype{C}{@{}>{\Centering\arraybackslash}m{0.14\linewidth}}


with suitable value for 0.14 in 0.14\linewidth. I have used \Centering command from ragged2e package inside the column. Also you will need [t] for tabular as in

 \begin{tabular}[t]{|C|c|}


MWE

\documentclass{article}
\usepackage{amsmath,array,ragged2e}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.14\linewidth}}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{Table1}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -19.0123  \\ \hline
2 & -16.4377 \\ \hline
3 & -13.3349 \\ \hline
4 & -11.7427  \\ \hline
5 & -10.1329 \\ \hline
6  & -9.0075 \\ \hline
7 & -6.0001 \\ \hline
\end{tabular}
%\quad
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{table2}  \\ \hline
A very long equation with k as input & Answer \\ \hline
1 & -16.0123  \\ \hline
2 & -12.4377 \\ \hline
3 & -9.5532 \\ \hline
4 & -5.7427  \\ \hline
5 & -4.1329 \\ \hline
6  & -3.0075 \\ \hline
7 & -3.0001 \\ \hline
\end{tabular}
%\quad
\begin{tabular}[t]{|C|c|}
\hline
\multicolumn{2}{|c|}{table3}  \\ \hline
$a+b+f+c+d+g+t+r+e+y+u+h+g+b+u+y+u+r+t+y=Z$ & Answer \\ \hline
1 & -5.0123  \\ \hline
2 & -2.4377 \\ \hline
3 & -3.3349 \\ \hline
4 & -1.7427  \\ \hline
5 & -1.1329 \\ \hline
6  & -1.0075 \\ \hline
7 & -1.0001 \\ \hline
\end{tabular}
\end{table}
\end{document}


Following the tradition of the site, vertical lines are evil and a table that uses booktabs is neat, here is a booktabs version:

\documentclass{article}
\usepackage{amsmath,array,ragged2e,booktabs}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.17\linewidth}}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{CcCcCc}
\toprule
\multicolumn{2}{c}{Table1} & \multicolumn{2}{c}{table2} & \multicolumn{2}{c}{table3}  \\ \midrule
A very long equation with k as input & Answer & A very long equation with k as input & Answer & A very long equation with k as input & Answer  \\ \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}
1 & -19.0123 &  1 & -16.0123 & 1 & -5.0123  \\
2 & -16.4377 &  2 & -12.4377 & 2 & -2.4377 \\
3 & -13.3349 &  3 & -9.5532  & 3 & -3.3349 \\
4 & -11.7427 &  4 & -5.7427  & 4 & -1.7427  \\
5 & -10.1329 &  5 & -4.1329  & 5 & -1.1329 \\
6 & -9.0075  &  6 & -3.0075  & 6 & -1.0075 \\
7 & -6.0001  &  7 & -3.0001  & 7 & -1.0001 \\\bottomrule
\end{tabular}
\end{table}
\end{document}


In the above tables, the number should have been in math mode (see the minus sign). To do that you can define another new column like

\newcolumntype{P}{>{$}c<{$}}


and use it as

\begin{tabular}[t]{CPCPCP}


Or.... use siunitx and its S column type:

\documentclass{article}
\usepackage{amsmath,array,ragged2e,booktabs,siunitx}
\newcolumntype{C}{>{\Centering\arraybackslash}m{0.17\linewidth}}
\newcolumntype{P}{S[table-format=3.4]}
\newcommand{\mc}[1]{\multicolumn{1}{c}{#1}}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{CPCPCP}
\toprule
\multicolumn{2}{c}{Table1} & \multicolumn{2}{c}{table2} & \multicolumn{2}{c}{table3}  \\ \midrule
A very long equation with k as input & \mc{Answer} & A very long equation with k as input & \mc{Answer} & A very long equation with k as input & \mc{Answer}  \\ \cmidrule(lr){1-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6}
1 & -19.0123 &  1 & -16.0123 & 1 & -5.0123  \\
2 & -16.4377 &  2 & -12.4377 & 2 & -2.4377 \\
3 & -13.3349 &  3 & -9.5532  & 3 & -3.3349 \\
4 & -11.7427 &  4 & -5.7427  & 4 & -1.7427  \\
5 & -10.1329 &  5 & -4.1329  & 5 & -1.1329 \\
6 & -9.0075  &  6 & -3.0075  & 6 & -1.0075 \\
7 & -6.0001  &  7 & -3.0001  & 7 & -1.0001 \\\bottomrule
\end{tabular}
\end{table}
\end{document}