Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

labeling side by side tables in latex

Tags:

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}
like image 899
Elham Avatar asked Nov 07 '25 20:11

Elham


2 Answers

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

like image 171
Matt Avatar answered Nov 12 '25 03:11

Matt


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}
like image 22
Werner Avatar answered Nov 12 '25 02:11

Werner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!