I have 2 tabular side by side. How can I label them as (a) and (b) and can be referred from text using \ref
.
\begin{tabular}{ccc}
\hline
a&b&c\\
\hline
\end{tabular}
\quad
\begin{tabular}{ccc}
\hline
d&e&f\\
\hline
\end{tabular}
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityYou will want to use the subcaption package for this purpose.
This package provides the subtable
environment for the goal you wanted to achieve. Please read section 3 of the
package documentation for details.
Please note how the \subref
command has been used to refer to the subtables. If you want to refer using both main number and subnumber (e.g. 1(a)), you will want to use the \ref
command. Format for all of these can be controlled. Please see the package documentation
for this feature. Another useful document is here.
Anyway, here is your code.
\documentclass{article}
\usepackage{subcaption}
\begin{document}
\begin{table}[!tbp]
\centering
\begin{subtable}[t]{0.4\textwidth}
\begin{center}
\begin{tabular}{ccc}
\hline
a&b&c\\
\hline
\end{tabular}
\caption{Table at left.}
\label{tab:left}
\end{center}
\end{subtable}
\quad
\begin{subtable}[t]{0.4\textwidth}
\begin{center}
\begin{tabular}{ccc}
\hline
d&e&f\\
\hline
\end{tabular}
\caption{Table at right.}
\label{tab:right}
\end{center}
\end{subtable}
\caption{This contains two subtables.}
\label{tab:main}
\end{table}
Please see the left~(\subref{tab:left}) and right~(\subref{tab:right})
tables.
\end{document}
And here is the output.
subcaption
package.