FAQ overflow

Great Answers to Questions About Everything

QUESTION

I’d like to have an environment that works much like a float, except that it doesn’t float.

That is, in fact, I’d like to be able to define an environment that has a label and a caption.

I explicitly do not want to use a floating environment, though. For one thing, floats do many things fancy which I just don’t need, nor want (such as spacing) and for another, floats have their share of problems (for example consider the problem of splitting a float between pages).

Is there a ready-made way to achieve this? Of course, I could always write my own based on the result of the other answer, i.e. harnessing \refstepcounter. But I’m not sure how to use that, documentation is scarce, and I’d prefer an existing solution.

ANSWER

You can use \captionof from either the caption or capt-of package:

\documentclass{article}
\usepackage{caption}

\DeclareCaptionType{mytype}[Typename][List of mytype]
\newenvironment{myenv}{}{}

\begin{document}
\listofmytypes

\section{abc}

\begin{myenv}
\captionof{mytype}{blub} something in my type
\end{myenv}

\end{document}