As noted in comments you could define an environment that does nothing if passed 1 but uses multicols otherwise:
\newenvironment{mymcol}[1]
{\ifnum#1=1
\let\endmulticols\par
\def\multicols##1{\par}%
\fi
\begin{multicols}{#1}}%
{\end{multicols}}
\makeatother
\begin{mymcol}{2}
\Column{
Name1 & Value1. \\
Name2 & Value2. \\
Name3 & Value3. \\
}
\Column{
Name4 & Value4. \\
Name5 & Value5. \\
}
\end{mymcol}
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}
Best Answer
This looks like an easy job for
siunitx
(aligning of the numbers) andbooktabs
(design of table, avoiding vertical rules, see the manual ofbooktabs
).Also, take a look at the
siunitx
manual and the siunitx tag as this package has a lot of options and possibilities to not only typeset numbers in tables.Code
Output