[Tex/LaTex] Adjustbox not showing caption with key option chosen

adjustboxtables

I can't get a caption to show up in the following MWE.

I've put caption at the end of the key list, and in the actual example the BLAH BLAH BLAH is replaced with an \input{table.tex} variant, but the problem persists in this simple version. \caption outside the environment just gives me a caption outside float environment error.

Any thoughts appreciated

\documentclass[10pt,landscape]{article}
\usepackage[left=0.5in,right=0.5in,top=0.5in,bottom=0.5in]{geometry}
\usepackage{adjustbox}
%\usepackage{caption}
\usepackage{booktabs}

\begin{document}

\renewcommand{\arraystretch}{1.5}

\begin{adjustbox}{width=\textwidth,totalheight=\textheight,keepaspectratio,caption={blah blah}}
BLAH BLAH BLAH
\end{adjustbox}


\end{document}

Best Answer

The caption key only sets the caption text. It will only be used if you also use a figure, float or nofloat key. The package manual states this:

caption=<caption text>
caption=[<short caption>]{<long caption>}

Defines a caption which will be used by a following figure, float or nofloat key. The position of the caption defaults to top for a table (non-)float and bottom for every other type.

If you don't want to turn the content into a float, use nofloat. Please note that you need to setup the caption type yourself using an appropriate package. This is not done for you by adjustbox. Also, there is no support for an unnumbered caption, e.g. just some title text etc., therefore using an existing float/caption type is mandatory.


Unfortunately the mentioned keys don't work directly with the width, height or totalheight keys because they don't force the execution of the outstanding resizing operations. Because of this the environment will try to resize the whole (non-)float environment which causes an error. I will fix this in the next version of adjustbox. In the meantime simply use a rotate=0 to force the resizing operation.


Here a minimal example where the adjusted content is taken as a table:

\documentclass{article}
\usepackage{adjustbox}

\begin{document}

\begin{adjustbox}{width=\textwidth,totalheight=\textheight,keepaspectratio,rotate=0,caption={blah blah},float=table}
BLAH BLAH BLAH
\end{adjustbox}

\end{document}