Rotating caption with image using a custom float

How do you rotate a caption with the image in a custom float?

I've tried the savebox and rotcaption methods outlined in this topic. My image rotates 90 degrees but my caption stays untouched and remains underneath the picture when it should rotate along with the image. Here is the code.

\documentclass{report}

\usepackage{caption}
\usepackage{float}
\usepackage{graphicx}
\usepackage{rotate}

\floatstyle{plain}
\floatname{example}{Example}
\newfloat{example}{h}{lop}

\begin{document}

\newsavebox{\myimage}

\begin{example}
\centering
\savebox{\myimage}{\rule{100pt}{150pt}}%
\rotatebox{90}{%
\begin{minipage}{\wd\myimage}
\includegraphics{picture1.jpg}
\caption{Here is the caption for this picture}
\end{minipage}}
\end{example}

\end{document}

• Do you want to use a landscape page ? – percusse Jul 22 '12 at 18:35

If using the newfloat package (instead of float) to define your custom float is an option, then your method works and also the mechanism offered by the hvfloat package:

\documentclass{report}
\usepackage{caption}
\usepackage{newfloat}
\usepackage{graphicx}
\usepackage{hvfloat}

\DeclareFloatingEnvironment[name=Example,placement=htbp,fileext=lop]{example}

\begin{document}

Some reference text

\newsavebox{\myimage}

\begin{example}
\centering
\savebox{\myimage}{\rule{100pt}{150pt}}%
\rotatebox{90}{%
\begin{minipage}{\wd\myimage}
\centering
\includegraphics[width=100pt]{ctanlion}
\caption{Here is the caption for this picture}
\label{ex;test2}
\end{minipage}}
\end{example}

\hvFloat[rotAngle=90,capWidth=w]%
{example}%
{\includegraphics[width=100pt]{ctanlion}}%
{Here is the caption for this picture}%
{ex:test2}

\end{document}


CTAN lion drawing by Duane Bibby.

Adding the option within=<counter>|none to \DeclareFloatingEnvironment, you can specify the counter which will be used to reset the counter of the floating environment. For example, within=none will result in a continuous numbering throughout the document.

• Thank you, this worked perfectly. Any way to change the numeration in the caption? It is showing the chapter and the figure number, i.e: Example 5.1 instead of Example 1. – Jacob Jul 22 '12 at 20:20
• @Jacob you can add the option within=none to \DeclareFloatingEnvironment, as in \DeclareFloatingEnvironment[name=Example,placement=htbp,fileext=lop,within=none]{example}. Please don't forget to accept my answer if you consider that it solved your problem (in case of doubt, please see How do you accept an answer?.) – Gonzalo Medina Jul 22 '12 at 20:27