Elham
Elham

Reputation: 867

labeling side by side tables in latex

I have two side by side tables in latex, however, I can not label them separately for using in ref tag. Is there any way to refer their name in my text using ref tag? For example, I need to say in table 1 ... and table 2 .....

Any comment?

\begin{table}[ht]
\parbox{.45\linewidth}{
\centering
\begin{tabular}{|l|l|l|}
    \hline
        person id & seq id & feature vector$_1$  \\\hline
        1 & 1 & 1 \\
        1 & 2 & 1 \\ \hline
        1 & 1 & 1 \\ \hline
        1 & 1 & 1 \\ \hline

    \end{tabular}
\caption{HRV Dataset}
    }
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tabular}{|l|l|l|l|}
\hline
person id & seq id & feature vector$_1$ & feature vector$_2$ \\\hline

1 & 1 &1 \\
1 & 2 & 1 \\ \hline
1 & 1 &1\\ \hline
1 & 1 & 1 \\ \hline
% \begin{tabular}{|l|l|l|l|}


% \end{tabular}
\end{tabular}
\caption{BAC Dataset}}
\end{table}

Upvotes: 3

Views: 13909

Answers (2)

Werner
Werner

Reputation: 15065

You should have no issue by adding \label either inside the \caption, or just after it, within the same construction (like \parbox or minipage - see below). I've also added some booktabs pizzaz...

enter image description here

\documentclass{article}

\usepackage{booktabs,makecell}

\begin{document}

\begin{table}
  \begin{minipage}{.5\linewidth}
    \centering
    \begin{tabular}{ *{3}{c} }
      \toprule
      \makecell{person \\ id} & \makecell{seq \\ id} & \makecell{feature \\ vector$_1$} \\
      \midrule
      1 & 1 & 1 \\
      1 & 2 & 1 \\
      1 & 1 & 1 \\
      1 & 1 & 1 \\
      \bottomrule
    \end{tabular}
    \caption{HRV Dataset}\label{tab:first}
  \end{minipage}%
  \begin{minipage}{.5\linewidth}
    \centering
    \begin{tabular}{ *{4}{c} }
      \toprule
      \makecell{person \\ id} & \makecell{seq \\ id} & \makecell{feature \\ vector$_1$} & \makecell{feature \\ vector$_2$} \\
      \midrule
      1 & 1 & 1 & 4 \\
      1 & 2 & 1 & 3 \\
      1 & 1 & 1 & 2 \\
      1 & 1 & 1 & 1 \\
      \bottomrule
    \end{tabular}
    \caption{BAC Dataset}\label{tab:second}
  \end{minipage}
\end{table}

See Table~\ref{tab:first} and Table~\ref{tab:second}\ldots

\end{document}

Upvotes: 3

Matt
Matt

Reputation: 1362

You can include the labels within the captions, this will allow you to \ref each of the tables separately later in the document.

\documentclass{article} 

\begin{document}

\begin{table}[ht]
    \parbox{.40\linewidth}{
        \centering
        \begin{tabular}{|l|l|l|}
            \hline
            person id & seq id & feature vector$_1$  \\\hline
            1 & 1 & 1 \\
            1 & 2 & 1 \\ \hline
            1 & 1 & 1 \\ \hline
            1 & 1 & 1 \\ \hline

        \end{tabular}
        \caption{HRV Dataset \label{HRVtable}}
    }
    \hfill
    \parbox{.45\linewidth}{
        \centering
        \begin{tabular}{|l|l|l|l|}
            \hline
            person id & seq id & feature vector$_1$ & feature vector$_2$ \\\hline

            1 & 1 &1 &1  \\
            1 & 2 & 1&1 \\ \hline
            1 & 1 &1 &1\\ \hline
            1 & 1 & 1 &1 \\ \hline
        \end{tabular}
        \caption{BAC Dataset \label{BACtable}}}
\end{table}

HRV data in Table \ref{HRVtable} and BAC data in Table \ref{BACtable}.

\end{document}

enter image description here

Upvotes: 4

Related Questions