1

I'm using packages framed to create my own quote environment with a nice frame. However, when using the package afterpage to shift a figure to the next page and the first thing on the next page is a frame, than the frame covers the caption of the figure. This does not happen if there's some text between the figure and the frame.

caption covered, if no text between picture and frame

How can I change my framed environment so that it does not cover the caption?

MWE:

\documentclass[12pt,a4paper,twoside,openany,fleqn]{book}
\usepackage[ngerman]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{framed}
\usepackage{changepage}
\usepackage{afterpage}

\definecolor{lightgray}{HTML}{F0F0F0}
\definecolor{darkerlightgray}{HTML}{E0E0E0}

\newenvironment{myQuote}{%
    \OuterFrameSep=0pt % space before and after box
  \def\FrameCommand{%
        \fboxsep=6pt %padding thickness
    \fcolorbox{darkerlightgray}{lightgray}%
  }%
  \MakeFramed{\hsize\linewidth\advance\hsize-\width\FrameRestore}%
  \noindent% disable indenting first paragraph
  \begin{adjustwidth}{}{7pt}%
  \vspace{-0.5\parskip}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed\vspace{-\parskip}%
}

\renewenvironment{quote}{\begin{myQuote}\em}{\end{myQuote}}

\begin{document}
\chapter{First Chapter}

\lipsum[2]

\afterpage{
    \begin{figure}[htp]
        \rule{\textwidth}{0.2\textheight}
            \caption{my first figure}
    \end{figure}
}

\lipsum[6]

\begin{quote}
    Quote OK
\end{quote}

\lipsum[6]

\begin{quote}
    Quote not OK (caption is covered)
\end{quote}

\lipsum[1]

\afterpage{
    \begin{figure}[htp]
            \rule{\textwidth}{0.2\textheight}
            \caption{my second figure}
    \end{figure}
}

\lipsum[1-2]

\begin{quote}
    Quote OK
\end{quote}

\lipsum[1]

\end{document}
0

I recognized, that tcolorbox handles footnotes differently than the framed package. Since I need all footnotes to be on the bottom of the page, I fiddled with the package code and came up with this solution:

\usepackage{etoolbox}

\makeatletter
\tracingpatches
\patchcmd{\MakeFramed}{\penalty\@M \vskip 2\baselineskip \vskip\height}{\penalty\@M \vskip 1pt \vskip\height}{}{}
\patchcmd{\MakeFramed}{\penalty9999 \vskip -2\baselineskip \vskip-\height}{\penalty9999 \vskip -1pt \vskip-\height}{}{}
\makeatother

I don't guarantee that this will work for all cases, however, the problem in the MWE and also other I had in my PhD thesis went away. Maybe someone can comment on whether this is a good solution or how to make it even better.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.