I need two tables to be placed on top of the page and side by side in a two-column document. Each table should have its own caption, in its own column, and needs to be nicely centered to its column.
So I tried this:
\begin{figure*}
\centering
\begin{minipage}{0.3\textwidth}
\centering
\begin{tabular}[c]{|c|c|}
\hline
1 & 2 \\
\hline
3 & 4 \\
\hline
\end{tabular}
\captionof{table}{table 1}
\end{minipage}
\begin{minipage}{0.3\textwidth}
\centering
\begin{tabular}[c]{|c|c|}
\hline
1 & 2 \\
\hline
3 & 4 \\
\hline
\end{tabular}
\captionof{table}{table 2}
\end{minipage}
\end{figure*}
And what it does is actually putting two small minpage
s at the center of the whole document regardless of any column geometry.
Since I previously used subfigure
and I know they nicely center in such scenarios I also tried:
\begin{figure*}
\begin{subfigure}{0.49\textwidth}
\centering
\begin{tabular}[c]{|c|c|}
\hline
1 & 2 \\
\hline
3 & 4 \\
\hline
\end{tabular}
\caption{table 1}
\end{subfigure}%
\hspace*{\fill}
\begin{subfigure}{0.49\textwidth}
\centering
\begin{tabular}[c]{|c|c|}
\hline
1 & 2 \\
\hline
3 & 4 \\
\hline
\end{tabular}
\caption{table 2}
\end{subfigure}
\end{figure*}
The ugly part is that I cannot have separate table captions that way (to the best of my knowledge, I cannot put table
in figure
). Nor can I use captionof{table}
in the figure
environment.
All in all, what do you suggest? How to have them nicely centered but still to have two separate table captions?
Why Mico's answer does not work? Seems like tables are not always centered.
\documentclass[twocolumn]{article}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
\begin{table*}
\begin{minipage}{\columnwidth}
\centering
\hrule
\resizebox{\columnwidth}{!}{%
\begin{tabular}{|c|c|}
\hline 1 & 2 \\ \hline 3 & 4 \\ \hline
\end{tabular}
}
\caption{table 1}
\end{minipage}\hfill % maximize the horizontal separation
\begin{minipage}{\columnwidth}
\centering
\hrule
\resizebox{\columnwidth}{!}{%
\begin{tabular}{|c|c|}
\hline 1 & 2 \\ \hline 3 & 4 \\ \hline
\end{tabular}
}
\caption{table 2}
\end{minipage}
\end{table*}
\lipsum[1-15] % filler text
\end{document}
Mico provided the solution to this problem; add %
after each tabular
. The idea is to suppress the space after tabular
. That spacing does not work well with \resizebox
. For more details see the comments to Mico's answer.
Best Answer
I suggest you use a
table*
environment (not afigure*
environment), 2minipage
environments (each of width\columnwidth
) within thetable*
environment, and centeredtabular
environments and\caption
directives within eachminipage
.