# Split the title of a table into more than one row

\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}
\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}
\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.

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

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


• @mrhappysmile I have added some more which may be of interest to you. – user11232 Feb 8 '15 at 15:48

You should consider using booktabs and ommit vertical lines, if you want to separate the tables, you could use subtable environments of subcaption:

\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage[width=0.9\linewidth,labelfont=bf]{caption}
\usepackage{subcaption}

\begin{document}

\begin{table}
\centering
\caption{Three equations evaluated at $k$}
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{c c}
\toprule
$k$ & Result \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{c c}
\toprule
$k$ & Result \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{c c}
\toprule
$k$ & Result \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\end{table}

\end{document}


I think you should also consider tou round the values, are 4 digits meaningfull and necessary? And You could use the S columntype of siunitx to get the numbers properly aligned at the decimal point (Note the Braces around the titles):

\documentclass{scrartcl}

\usepackage{booktabs}
\usepackage[width=0.9\linewidth,labelfont=bf]{caption}
\usepackage{subcaption}

\usepackage{siunitx}

\begin{document}
\pagestyle{empty}

\begin{table}
\centering
\caption{Three equations evaluated at $k$}
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
\toprule
{$k$} & {Result} \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
\toprule
{$k$} & {Result} \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\begin{subtable}{0.33\textwidth}
\centering
\caption{Complicated function of $k$}
\begin{tabular}{S[table-format=1.0] S[table-format=-2.4]}
\toprule
{$k$} & {Result} \\
\midrule
1 & -19.0123  \\
2 & -16.4377 \\
3 & -13.3349 \\
4 & -11.7427  \\
5 & -10.1329 \\
6  & -9.0075 \\
7 & -6.0001 \\
\bottomrule
\end{tabular}
\end{subtable}%
\end{table}
\end{document}


You should also note that siunitx uses the correct minus sign, not a hyphen, and uses the monospaced figures.