Graphics, Figures & TablesSide by Side Tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mdk31
Posts: 20
Joined: Wed Mar 11, 2009 4:38 am

Side by Side Tables

Post by mdk31 »

I'm trying to put two tables side by side and I'm not sure how to go about doing it. I was looking at the subfigure package but I think that it's just for actual images.

Code: Select all

\begin{figure}[H]
\centering
\begin{tabular}{ | l | l |}
\hline
Current (A) & Mean B (G) \\ \hline
0.5 & 9.3 \\ \hline
1.0 & 16.5 \\ \hline
1.5 & 23.4 \\ \hline
2.0 & 30.2 \\ \hline
2.5 & 40.3 \\ \hline
3.0 & 48.2 \\ \hline
3.5 & 53.9 \\
\hline
\end{tabular}
\caption{Current and Mean B with a Forward Polarity}
\end{figure} 

\begin{figure}[H]
\centering
\begin{tabular}{ | l | l |}
\hline
Current (A) & Mean B (G) \\ \hline
-0.5 & -8.8 \\ \hline
-1.0 & -17.1 \\ \hline
-1.5 & -25.2 \\ \hline
-2.0 & -32.6 \\ \hline
-2.5 & -40.1 \\ \hline
-3.0 & -47.7 \\ 
\hline
\end{tabular}
\caption{Current and Mean B with a Reversed Polarity}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
grbn
Posts: 6
Joined: Fri Mar 27, 2009 3:58 pm

Side by Side Tables

Post by grbn »

You can indeed use the subfigure package, it handles tables too. See its manual. Just use something like:

Code: Select all

\begin{table}[h!]
\vspace{5pt}
    \begin{center}
        \subtable
            {
                \begin{tabular}{l}
                
                \end{tabular}\centering
            }
        \subtable
            {
            \begin{tabular}{l|r}
            

\end{tabular}\centering
            }
    
        \caption{}
        \label{}
    \end{center}
    
\end{table}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Side by Side Tables

Post by gmedina »

Hi,
grbn wrote:You can indeed use the subfigure package, it handles tables too...
subfigure is an obsolete package and shouldn't be used anymore. The subfig package has superseded it, and should be used in its stead. Another options (besides using the subfig package):

1) Use minipages and the \captionof command provided by the caption package.
2) Use the subcaption package (a little, yet useful, companion to the caption package).
1,1,2,3,5,8,13,21,34,55,89,144,233,...
mdk31
Posts: 20
Joined: Wed Mar 11, 2009 4:38 am

Side by Side Tables

Post by mdk31 »

Thanks for your response.

My two main problems though are how to get each table labeled separately (as Table 1 and Table 2).

I tried

Code: Select all

\subtable[caption]
but the .pdf output gives, under the table, "(a) caption" rather than "Table 1: Caption". Also, since the tables are not equal length, they both end up centered which makes them look not quite right. I want to be able to align their top rows together.
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Side by Side Tables

Post by gmedina »

Hi,

as I suggested before, you could use minipages and the \captionof command. As for the vertical alignment, I would recommend you to align the tables at the bottom, so their captions will be aligned too. Please have a look at the following simple example:

Code: Select all

\documentclass{book}
\usepackage{caption}

\begin{document}

\begin{minipage}[b]{.40\textwidth}
  \centering
  \begin{tabular}{ | l | l |}
    \hline
    Current (A) & Mean B (G) \\ \hline
    0.5 & 9.3 \\ \hline
    1.0 & 16.5 \\ \hline
    1.5 & 23.4 \\ \hline
    2.0 & 30.2 \\ \hline
    2.5 & 40.3 \\ \hline
    3.0 & 48.2 \\ \hline
    3.5 & 53.9 \\
    \hline
  \end{tabular}
  \captionof{table}{Current and Mean B with a Forward Polarity}
  \label{tab:forpol}
\end{minipage}\qquad
\begin{minipage}[b]{.40\textwidth}
  \centering
  \begin{tabular}{ | l | l |}
    \hline
    Current (A) & Mean B (G) \\ \hline
    -0.5 & -8.8 \\ \hline
    -1.0 & -17.1 \\ \hline
    -1.5 & -25.2 \\ \hline
    -2.0 & -32.6 \\ \hline
    -2.5 & -40.1 \\ \hline
    -3.0 & -47.7 \\
  \hline
  \end{tabular}
  \captionof{table}{Current and Mean B with a Reversed Polarity}
  \label{tab:revpol}
\end{minipage}

\end{document}
However, if you still want your tables aligned at the top, please let me know, indicating also whether or not you want the captions to be aligned too.

Remark: make sure that you have a recent version (3.1x) of the caption package installed in your system.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
mdk31
Posts: 20
Joined: Wed Mar 11, 2009 4:38 am

Re: Side by Side Tables

Post by mdk31 »

The problem is that I don't think the caption package. is updated on my system. I'm writing it on emacs out of one of our universities "machines." I don't really know how to explain it and I'm not sure how I would update the caption package.
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Re: Side by Side Tables

Post by phi »

You can always install packages in a private texmf tree, for example in ~/texmf on Linux or ~/Library/texmf on OS X.
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Side by Side Tables

Post by Juanjo »

The caption package and the \captionof command are not necessary in this case. It suffices to put both minipages inside the same table environment and use \caption, e.g.:

Code: Select all

\documentclass{book}

\begin{document}

\begin{table}
\begin{minipage}[b]{.40\textwidth}
  \centering
  \begin{tabular}{ | l | l |}
    \hline
    Current (A) & Mean B (G) \\ \hline
    0.5 & 9.3 \\ \hline
    1.0 & 16.5 \\ \hline
    1.5 & 23.4 \\ \hline
    2.0 & 30.2 \\ \hline
    2.5 & 40.3 \\ \hline
    3.0 & 48.2 \\ \hline
    3.5 & 53.9 \\
    \hline
  \end{tabular}
  \caption{Current and Mean B with a Forward Polarity}
  \label{tab:forpol}
\end{minipage}\qquad
\begin{minipage}[b]{.40\textwidth}
  \centering
  \begin{tabular}{ | l | l |}
    \hline
    Current (A) & Mean B (G) \\ \hline
    -0.5 & -8.8 \\ \hline
    -1.0 & -17.1 \\ \hline
    -1.5 & -25.2 \\ \hline
    -2.0 & -32.6 \\ \hline
    -2.5 & -40.1 \\ \hline
    -3.0 & -47.7 \\
  \hline
  \end{tabular}
  \caption{Current and Mean B with a Reversed Polarity}
  \label{tab:revpol}
\end{minipage}
\end{table}

\end{document}
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
Post Reply