# How to make table with caption appearing on \listoftables without \begin{table} environment? [duplicate]

Here is an example of LaTeX document being compiled with pdflatex having

• table with caption

:

\documentclass[a5paper,12pt,twoside,openany]{report}
\usepackage[a5paper]{geometry}
\usepackage{fullpage}
\begin{document}

\begin{table}[htbp]
\begin{center}
\label{mytable}
\caption{mytable}
\begin{tabular}{ll}
\hline
A & B \\
C & D \\
\hline
\end{tabular}
\end{center}
\end{table}

\listoftables
\end{document}


How to make a table, without \begin{table}...\end{table} float, preserving style of table (table having caption, label), and appearing in hyperlinked \listoftables ?

(Situation: Currently I work on document where I have such tables, and I would like to put some of them without floats to force placement or tables and footnotes relating to them.)

-

## marked as duplicate by Marco Daniel, lockstep, cmhughes, egreg, SeamusFeb 11 '12 at 19:38

–  cmhughes Feb 10 '12 at 17:53

With caption.sty you can use \captionof{<type>} or \captionsetup{type=table}.

If you want to make a new (non-floating) environment, e.g. mytab, i suggest to use the \captionsetup-way. If you want to access the captions somewhere in the document (as in you pastebin example*) \captionof is your friend; you may wrap it in a new command like \tabcap:

\documentclass{article}

\usepackage{caption}

\usepackage{lipsum}

% Environment
\newenvironment{mytab}{%
\begin{center}
\captionsetup{type=table}
}{\end{center}}

% Shortcut
\def\tabcap{\captionof{table}}

\begin{document}
\listoftables

\lipsum[1]

% Somewhere with \captionof
\begin{center}
\rule{\textwidth}{2cm}
\captionof{table}{Caption text}
\end{center}

\lipsum[2]

% Somewhere with shrtcut \tabcap
\begin{center}
\rule{\textwidth}{2cm}
\tabcap[Optional]{Caption text}
\end{center}

\lipsum[3]

% Environment
\begin{mytab}
\rule{\textwidth}{2cm}
\caption{Caption text}
\end{mytab}

\end{document}


* Please note that it’s preferred to edit your original question to add information and code and not to use external sites.

-
Do I get you right, that key of your answer is "use \captionof{}{} ? Could you ensure me that I understand you and take a look at this LaTeX toy-example pastebin.com/AGvmGw8J ? –  Grzegorz Wierzowiecki Feb 11 '12 at 11:39
This works ! :) Table is constructed 'right there' as I expected ! –  Grzegorz Wierzowiecki Feb 11 '12 at 16:23
@GrzegorzWierzowiecki: There are two keys in my answer. I improved it an hope I clarified it :-) –  Tobi Feb 11 '12 at 17:21

I believe that what you want can be acheived with float package and [H] (meaning "here and nowhere else) placement specification. Remember that you must run LaTeX twice to get correct list of tables.

\documentclass[a5paper,12pt,twoside,openany]{report}
\usepackage[a5paper]{geometry}
\usepackage{fullpage}

\usepackage{float} %% <--- this

\begin{document}

\begin{table}[H] %% <--- and this
\begin{center}
\label{mytable}
\caption{mytable}
\begin{tabular}{ll}
\hline
A & B \\
C & D \\
\hline
\end{tabular}
\end{center}
\end{table}

\listoftables
\end{document}

-
I can find this post, but I've seen somewhere on this site "always provide alternative options, if you want to use only [h] - you do not want to use floats" (if someone finds post, please, leave comment). What you've point out, I ensure is "here if it fits" - according to tex.stackexchange.com/questions/39017/… . Your suggestion about "[H]" appeared earlier tex.stackexchange.com/a/9486/7128 and it's good to mention here. However, I'm looking for "manual construction" of "table" without float. –  Grzegorz Wierzowiecki Feb 11 '12 at 10:09
Well, actually this is the manual construction, just it is called {table}[H]. the table environment in this case does nothing less and nothing more than 1) typeset its content in the "main flow" (meaning no floating at all), 2) make a line in the list of tables and 3) allow \caption command. I believe that it is exactly what you seek for. –  yo' Feb 11 '12 at 15:54
Are you sure you have loaded the package float, i.e. do you have \usepackage{float} in your preamble? –  yo' Feb 11 '12 at 19:52
Forgive me, I've missed it. Now, on double-checking I've found there is no package float. Thanks for help, I will remember for future. –  Grzegorz Wierzowiecki Feb 11 '12 at 20:01