# How to caption/subcaption a tabular? easily

I few week ago, I learned subcaption figuras, with subcaption packages, and I like it very much.

Now I would like to caption/subcaption tabulars.

I was vieweing any issues and all have a table enviroment OVER the \begin{tabular} \end{tabular}

What´s the best and easy way to caption/subcaption a tabular??

like this....

\documentclass[12pt,a4paper,x11names]{article}
\usepackage[top=2.5cm, left=3.5cm, bottom=2.5cm, right=2.5cm]{geometry}

\usepackage{lipsum,mwe}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

\begin{document}
Hello,\\

\begin{tabular}{|c|c|r|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a & e & 12 \\
\hline
f & g & 3 \\
\hline
\end{tabular}

\end{document}

• Use \begin{table} ... \end{table} around your tabular environment and insert a \caption or \subcaption as in the case with a figure
– user31729
Jun 11, 2014 at 12:56
• Normally captions are only attached to "floats" (i.e. things like figures, tables, etc, that can 'float' to the top or bottom of a page). A tabular object is an inline object, not a float. As @ChristianHupfer says above, you can convert it to a float by wrapping the tabular object in a table environment. Jun 11, 2014 at 12:57
• Thank you to the two. I use latex, but I can´t understand weell what float enviroments is, I need to get a strong base on latex. Thank you. So... I can use the subcaption package as I do with figures and images. Yes? Jun 11, 2014 at 13:03
• @MikaIke: Yes, as long there is a \begin{table} ...\end{table} instead of \begin{figure}...\end{figure}
– user31729
Jun 11, 2014 at 13:05

Repeating the suggestions provided in the comments: Place the existing tabular environment inside a table environment. It is common -- though not mandatory -- to center the material inside a table environment. The command \centering achieves that objective. The table and figure environments are "floats", i.e., unless you explicitly instruct LaTeX not to do so, LaTeX will place them where it thinks it's best. For much more on floats and the LaTeX algorithm that determines float placement, see the posting How to influence the position of float environments like figure and table in LaTeX?

The table environment can be given a \caption and a \label. Assigning labels is useful if you want to cross-reference the table somewhere else in your document using the TeX/LaTeX command \ref.

If you do a lot of cross-referencing -- not only to tables, but to sections, figures, page numbers, etc -- you may want to get to know the cleveref package and its command \cref. For more on LaTeX's cross-referencing mechanisms and packages that provide enhanced cross-referencing macros see the posting Cross-reference packages: which to use, which conflict?

Here, finally, is your tabular environment encased in a table environment, with a couple of cross-referencing commands thrown in for good measure.

\documentclass[12pt,a4paper,x11names]{article}
\usepackage[vmargin=2.5cm, left=3.5cm, right=2.5cm] {geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}
\usepackage[spanish]{cleveref} %% new

\begin{document}
Hello, \dots

\begin{table}[h]  %% new
\centering        %% new
\caption{A simple table} %% new
\label{tab:simple}       %% new
\begin{tabular}{|c|c|r|}
\hline
% after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
a & e & 12 \\
\hline
f & g & 3 \\
\hline
\end{tabular}
\end{table} %% new

Here's a cross-reference to table \ref{tab:simple}.  %% new

Here's a cross-reference to \cref{tab:simple}.  %% new
\end{document}

• Thank you very much. Your answer was very usefull to me. one thing: I see in refferes thw use of fig:, tab: , sec: and I suposse is to keep order and know what type of object is (I like cref writes"figura 3" instead of only "3" :-) Yes. but... What are the advantages of use fig:, tab:? I know 2: ordering reading a .tex, and let cref insert the words "figure"/"table" but.. any other advantantages??? Jun 12, 2014 at 8:42
• I think that you speack spanish :-) for the line \usepackage[spanish]{cleveref}. How can I change the word "Cuadro" with the word "Tabla"? in cref Jun 12, 2014 at 8:43
• @MikaIke - You could type \crefname{table}{Tabla}{Tablas} to change the name of tables. Using prefixes such as tab:, fig:, and sec: inside labels is strictly optional; it does tend to simplify keeping track of various labels...
– Mico
Jun 12, 2014 at 11:24