1

Possible Duplicate:
Label and caption without float
Create caption without float AND without caption-package?

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

  • table with caption
  • hyperlinked list of tables

:

\documentclass[a5paper,12pt,twoside,openany]{report}
\usepackage[a5paper]{geometry}
\usepackage{fullpage}
\usepackage[colorlinks]{hyperref}
\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.)

2 Answers2

2

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.

Tobi
  • 56,353
1

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[colorlinks]{hyperref}

\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}
David Carlisle
  • 757,742
yo'
  • 51,322
  • 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 http://tex.stackexchange.com/questions/39017/how-to-influence-the-position-of-float-environments-like-figure-and-table-in-lat . Your suggestion about "[H]" appeared earlier http://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