# Sideways figure and caption to fit textwidth and no page break

I'm struggling with placing some plots in latex. I'm trying to include the plots (sideways, but not the heading) in an appendix, so the first plot needs to be placed at the same page as the appendix heading. Also the plots, including the caption need to be placed inside the top/bottom/left/right margins. When using sidewaysfigure i get (1) a pagebreak, such that the heading and plot are placed at two different pages and (2) when the caption is long, it gets outside the margins.

Is there any way I can prevent the pagebreak? and how to prevent the plot and caption to break the margins? (is there any way to measure the total height of plot and caption, and scale the plot (graphic) so that it has width=textheight (inside margins?), and height=textwidth(inside margins?)-"captionheight"....

my preamble

\documentclass[pdftex,10pt,b5paper,twoside]{report}
\usepackage[lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry}


and

\begin{sidewaysfigure}
\captionsetup{width=0.75\textwidth}
\begin{center}
\includegraphics[keepaspectratio=true, width=\textwidth]{./Figur/fundvar.png}
\caption[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}
\label{fig:fundvar}
\end{center}
\end{sidewaysfigure}

-
Why do you asked the question again?: tex.stackexchange.com/questions/20026/… – Marco Daniel Jun 7 '11 at 11:01

You could use the hvfloat package:

\documentclass[pdftex,10pt,b5paper,twoside]{report}
\usepackage[showframe,lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry}
\usepackage[demo]{graphicx}
\usepackage{hvfloat}

\begin{document}

\appendix
\chapter{Test chapter}

\hvFloat[%
floatPos=htb,%
capVPos=c,%
rotAngle=90,
objectPos=c]{figure}{\includegraphics[width=353pt,height=290pt]{image}}%
[Commercial crude oil inventories, SPX excess returns, S\&P GCSI excess return time series]{Commercial crude oil inventories calculated as the logarithm of the current value divided by the mean of same weekly values over the past 5 years, Log excess returns on the S\&P Goldman Sachs Commodity Index,  Log excess returns on the S\&P 500 index.}{fig:test}

\end{document}


The demo option for graphicx was used to make my example compilable for everyone; do not use the option in your actual code.

-
any way to make i rotate "automatically" as the sideways figure and prevent the caption from disappearing out of the page (instead decrease the height of the figure)? (have multiple plots with different caption lengths..) – latexmp Jun 6 '11 at 21:33
@latexmp: the rotAngle key allows you to specify the angle. The other question requires more work, and unfortunately, I don't have much time now; perhaps you can adapt Martin's answer to tex.stackexchange.com/q/14512/3954 – Gonzalo Medina Jun 6 '11 at 21:44
thanks, I was thinking of automatically rotating because of twoside printing, so that the top of the figure is always towards the middle of the "book". I would like it to do this by itself, since I have a lot of graphs/plots.... – latexmp Jun 6 '11 at 21:52