[Tex/LaTex] Force sideways graphic to fit page

graphicsrotatingscaling

I'm using this preamble:

\documentclass[pdftex,10pt,b5paper,twoside]{report}
\usepackage[lmargin=25mm,rmargin=25mm,tmargin=27mm,bmargin=30mm]{geometry}
\usepackage[comma]{natbib}
\usepackage{lmodern}
\usepackage{setspace}
\usepackage{amsmath,amssymb,amsfonts} 
\usepackage{graphics}                 
\usepackage{color}              
\usepackage{hyperref}             
\usepackage{graphicx}
\usepackage{listings}
\usepackage{courier}             
\usepackage{longtable}
\usepackage{rotating}
\usepackage{calc}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{ctable}
\usepackage{mathtools}

I need to include some plots with captions (sideways) and I use:

\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}

The captions have different lengths, so how can force latex to fit the plot and caption to the page (inside the margin specified) and also keeping the aspect ratio of the plot?

EDIT: Also, latex always put sideways figures on a new page. If i try to put

 \section{Variables}

the sidewaysfigure is placed on the next page, any way to prevent this?

Best Answer

Here is an example of my solution some days before. I am using the package hvfloat. I know the package units is obsolete. siunitx is much better.

\documentclass[11pt, a4paper, twoside]{report}
\usepackage{geometry}
\usepackage{amsmath,amsfonts,amssymb,amsxtra}
\usepackage{booktabs}


\usepackage{hvfloat}
\usepackage{units}



\begin{document}
\listoftables
\clearpage
\section{minimalbeispiel}
\vfill
\begin{center}
\hvFloat[%
nonFloat=true,%
capPos=l,%
capAngle=90,%
objectAngle=90,%
]{table}{\tiny%
\begin{tabular}{llllllll}
\toprule
& \multicolumn{4}{c}{Coefficients} & & \\
\cmidrule(lr){2-5}
Clamp. pres. in bar & $b_0$ & $b_1$ & $b_2$ & $b_3$ & $SS_{\text{err}}$ & $R^2$ in \%\\
\midrule
15 & $9.63*10^{-1}$ & $-2.16*10^{-3}$ & $3.56*10^{-6}$ & $-3.38*10^{-9}$ & $6.16*10^{-4}$ & 99.88\\
20 & $9.62*10^{-1}$ & $-2.08*10^{-3}$ & $3.40*10^{-6}$& $-3.27*10^{-9}$ & $8.19*10^{-4}$ & 99.83\\
25 & $9.64*10^{-1}$ & $-2.08*10^{-3}$ & $3.46*10^{-6}$ & $-3.29*10^{-9}$ & $5.30*10^{-4}$ & 99.89\\
30 & $9.61*10^{-1}$ & $-1.99*10^{-3}$ & $3.19*10^{-6}$ & $-3.00*10^{-9}$ & $6.99*10^{-4}$ & 99.84\\
35 & $9.53*10^{-1}$ & $-1.98*10^{-3}$ & $3.09*10^{-6}$ & $-2.92*10^{-9}$ & $6.87*10^{-4}$ & 99.85\\
40 & $9.53*10^{-1}$ & $-2.04*10^{-3}$ & $3.33*10^{-6}$ & $-3.22*10^{-9}$ & $5.84*10^{-4}$ & 99.88\\
45 & $9.54*10^{-1}$ & $-2.06*10^{-3}$ & $3.20*10^{-6}$ & $-3.02*10^{-9}$ & $5.24*10^{-4}$ & 99.89\\
\bottomrule
\end{tabular}%
}%
[Polarization curve data fitting of clamping pressure testing]{%
Polarization curve data fitting of clamping pressure testing\\ Model: $\frac{U}{V} = b_0 + b_1 \frac{i}{\unitfrac[]{\text{mA}}{\text{cm}^2}} + b_2 \frac{i^2}{\left(\unitfrac[]{\text{mA}}{\text{cm}^2}\right)^2} + b_3 \frac{i^3}{\left(\unitfrac[]{\text{mA}}{\text{cm}^2}\right)^3}$}{tab:3}
%
\hvFloat[%
nonFloat=true,%
capPos=l,%
capAngle=90,%
objectAngle=90,%
]{table}{\tiny%
\begin{tabular}{llllll}
\toprule
& \multicolumn{3}{c}{Coefficients} & & \\
\cmidrule(lr){2-4}
\tiny{Curr. dens. in \unitfrac{mA}{cm\textsuperscript{2}}} & $b_0$ & $b_1$ & $b_2$ & $SS_{\text{err}}$ & $R^2$ in \%\\
\midrule
100 & $7.35*10^{-1}$ & $2.35*10^{-3}$ & $-4.09*10^{-5}$ & $2.98*10^{-5}$ & 76.12\\
200 & $6.09*10^{-1}$ & $3.91*10^{-3}$ & $-6.64*10^{-5}$ & $3.21*10^{-5}$ & 87.97\\
300 & $4.76*10^{-1}$ & $6.83*10^{-3}$ & $-1.16*10^{-4}$ & $5.13*10^{-5}$ & 93.34\\
400 & $3.82*10^{-1}$ & $6.40*10^{-3}$ & $-1.08*10^{-4}$ & $3.66*10^{-5}$ & 94.47\\
480 & $2.58*10^{-1}$ & $9.11*10^{-3}$ & $-1.53*10^{-4}$ & $7.52*10^{-5}$ & 94.23\\
560 & $1.69*10^{-1}$ & $8.80*10^{-3}$ & $-1.47*10^{-4}$ & $1.55*10^{-4}$ & 88.06\\
640 & $1.88*10^{-2}$ & $1.18*10^{-2}$ & $-1.94*10^{-4}$ & $2.28*10^{-4}$ & 89.73\\
\bottomrule
\end{tabular}%
}
[Cell voltage over clamping pressure data fitting parameters]{Cell voltage over clamping pressure data fitting parameters\\ Model: $\frac{U}{V} = b_0 + b_1 \frac{p}{\text{bar}} + b_2 \frac{p^2}{\left(\text{bar}\right)^2}$}{tab:2}
\end{center}
\vfill\clearpage
\end{document}