[Tex/LaTex] how to maximise a figure (float) size

floatsgraphicssidewaysfigure

Is it possible to maximise the size of the whole float (including the caption)? I would like the float to fit the maximum allowable size (both width and height) on the page (i.e. for binding). I have included an example, which makes the figure too large for the page and cuts off the caption. I also use a package from my university that sets the margin size, etc.

\documentclass{report}
\usepackage{mwe}
\usepackage{rotating}
\begin{document}

\begin{sidewaysfigure}[p]
        \includegraphics[height=1\textheight,width=1\textwidth]{example-image-a}
    \caption{long figure caption...long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption...
            long figure caption... 
            END OF CAPTION}
    \label{fig:example}
\end{sidewaysfigure}

\end{document}

Best Answer

A simple solution, but it needs manual adjustment:

enter image description here

\documentclass{report}
\usepackage[showframe, % only for show page layout
            margin=25mm]{geometry}
\usepackage{mwe}
\usepackage{rotating}

\newlength{\imageheight}% added
\setlength\imageheight{\dimexpr\textwidth-\abovecaptionskip}% added
\begin{document}
    \begin{sidewaysfigure}
\includegraphics[width=\textheight,% changed
                 height=\dimexpr\imageheight-2\baselineskip\relax% changed, number of \baselineskip adjust manulaly :-(
                 ]{example-image-a}
\caption{long figure caption... long figure caption... long figure caption...  
        long figure caption...  long figure caption...  long figure caption...
        long figure caption...  long figure caption...  long figure caption...  
        long figure caption...  long figure caption...  long figure caption...
        END OF CAPTION}
    \label{fig:example}
\end{sidewaysfigure}
\end{document}

Note: \textwidth doesn't work as expected. Therefore in preamble is defined new length and set to textwidth-\abovecaptionskip. Space, needed for caption is determined in graphics option by manually set number of caption lines in it calculation.

Addendum: In case of image in the portrait format, the code is simpler. You not need sidewaystable and therefore the height of image can be calculated in includegraphics options field:

\documentclass{report}
\usepackage[showframe, % only for show page layout
            margin=25mm]{geometry}
\usepackage{mwe}
\usepackage{rotating}

\begin{document}
    \begin{figure}[p]
\includegraphics[height=\dimexpr\textheight-3\baselineskip-\abovecaptionskip\relax,
                 width=\textwidth% 
                 ]{example-image-a}
\caption{long figure caption... long figure caption... long figure caption...  
        long figure caption...  long figure caption...  long figure caption...
        long figure caption...  long figure caption...  long figure caption...  
        long figure caption...  long figure caption...  long figure caption...
        END OF CAPTION}
    \label{fig:example}
    \end{figure}
\end{document}

enter image description here

Related Question