1

I have an image in my document that I want to display as big as possible in landscape orientation but the whole figure (image AND caption) should be within the limits of the body.

I researched a lot how to define the size for the whole figure environment and the most suggested solution was to replace the figure by a minipage. However, I don't get the result I want to have.

MWE for the minipage approach:

\documentclass[a4paper, DIV=13, 12pt]{scrreprt}

\usepackage{graphicx} \usepackage{caption} \usepackage{pdflscape} \usepackage{lipsum}

\title{This is the Title} \author{It's a Me, Mario!}

\begin{document} \maketitle

\chapter{Chapter} \lipsum[6]

\begin{landscape} \begin{minipage}[t][\textheight][t]{\linewidth} \centering
\noindent\includegraphics[height=\textheight,keepaspectratio]{example-image-a} \captionof{figure}{This is the long version of the description of the caption} \label{fig:flussdiagramm}
\end{minipage} \end{landscape}

\chapter{Chapter} \lipsum[5]

\end{document}

But the problem stays the same: The caption is outside of the body. Here's what I mean: enter image description here

The margin of the caption (red arrow) does not match the margin of the other pages (blue arrows).

I thought, that a minipage redefines the \textheight and \linewidth but it seems that this is not the case. Can anybody confirm this?

How can I make sure, that the caption is within the body/text area and the margins stay the same on each page?

Best, Korbinian

  • 3
    if you have \includegraphics[height=\textheight, the image will be full height and not leave room for a caption – David Carlisle Apr 12 '23 at 11:24
  • Is there an existing length for the height of the caption, so that I can substract it from the image's height?

    I saw some solutions where people calculate the height but is this really the easiest way/best practice for this?

    – Korbinian Hutter Apr 12 '23 at 11:28
  • no you can write a 20-line caption, so if you want that you would have to set the caption text in a box first and measure before setting the image – David Carlisle Apr 12 '23 at 11:31
  • Makes sense, thank you!

    @Others: I did the calculation with Frank Mittelbach's answer (first code block) on this post: https://tex.stackexchange.com/a/47185/261955

    It worked for me. You can also keep the figure environment and don't need a minipage.

    – Korbinian Hutter Apr 12 '23 at 13:57
  • For the sake of completeness:

    I thought, that a minipage redefines the \textheight and \linewidth but it seems that this is not the case.

    Can anybody confirm this?

    – Korbinian Hutter Apr 13 '23 at 14:15

1 Answers1

1

As @David Carlisle wrote, the height of the caption has to be calculated during the compilation of the document to determine the height available for the image.

I used @Frank Mittelbach's answer on this post for the calculation. This piece of code works well for me:

\usepackage{calc}
\newlength\graphht              % holds the height available for the image
\newcommand\calculategraphicstargetheight[1]{%    % pass the number of lines of the caption
     \setlength\graphht{\textheight 
                       -\parskip
                       -\abovecaptionskip -\belowcaptionskip
                       -(\baselineskip * #1)
                       }}

Use it like this:

\begin{landscape}
    \calculategraphicstargetheight{1}
    \begin{figure}[htbp]
        \centering
        \noindent\includegraphics[width=\linewidth,height=\graphht,keepaspectratio]{example-image-a}
        \captionof{figure}{This is the long version of the description of the caption}
        \label{fig:niceimage}
    \end{figure}
\end{landscape}

The result is as follows:

The caption is no longer outside of the document's body

Korbinian