You can now use the adjustbox
package to turn your boxed stuff into a non-floating float replacement using the nofloat=<type>
key. Caption and label can be added by own keys, before the nofloat
. For centering the center
key can be used. To add the vertical space use the vspace
key. This solution has the benefit, that you can also use all the many other features of adjustbox
to modify the content (min/max scaling, framing, etc.)
Note that if the figure content is just a single image you can just use the same keys on \adjustbox
and get a one-liner. If all you want is a tabular then there is the tabular
key for {adjustbox}
.
If you later want to change it to a real float just turn nofloat
to float
and remove the vspace
key. adjustbox
places the caption on top for table
s and on bottom for figure
s. This can be changed by using the keys captionbelow
or captionabove
instead of caption
.
See the adjustox
manual for all options.
If you don't want to box the content you can still use the adjustbox
package as it provides the {adjnofloat}{<type>}
environment. It is used internally to implement the nofloat
key. Users can either redefine this environment to change or patch the nofloat
behavior or use the environment directly. The environment uses code very similar as in Herberts answer.
Usage examples:
\documentclass{article}
\usepackage{blindtext}% for example text here only
\usepackage{adjustbox}
\begin{document}
\blindtext
\begin{adjustbox}{center,caption={some caption},label={somelabel},nofloat=figure,vspace=\bigskipamount}
% maybe other stuff
\includegraphics[width=\textwidth]{example-image}% example only, could also be \adjustimage
% maybe other stuff
\end{adjustbox}
\blindtext
% For simple images, a one liner is enough
\adjustimage{width=\textwidth,center,caption={some caption},label={somelabel},nofloat=figure,vspace=\bigskipamount}{example-image}
\blindtext
\begin{adjustbox}{center,caption={some caption},label={somelabel},nofloat=table,vspace=\bigskipamount}
% maybe other stuff
\begin{tabular}{lll}
some & tabular & is\\
also & possible & with this \\
\end{tabular}
% maybe other stuff
\end{adjustbox}
\blindtext
% For just a tabular:
\begin{adjustbox}{tabular=lll,center,caption={some caption},label={somelabel},nofloat=table,vspace=\bigskipamount}
some & tabular & is\\
also & possible & with this \\
\end{adjustbox}
\blindtext
\end{document}
Part of the result:
center
environment but the\centering
command for figures. See Should I use center or centering for figures and tables?\FloatBarrier
somewhere between the figure and the paragraph. It forces all figures defined before the command to render before that point in text. You will need to add\usepackage{placeins}
in the preamble to use the command. Sometimes, I have found this very useful.