This question is somewhat related to my previous question overfull hbox on chapters with line above/below chapter title using KOMA-script, as (parts of) the issue occurs with various/all methods of adding the top and bottom lines (not only mdframed which I found to be the easiest to control).
Given the following minimal example to showcase the issue
\documentclass[
parskip=full,
open=any,
]{scrreprt}
\usepackage{mdframed}
\usepackage{lipsum}
\RedeclareSectionCommand[
beforeskip=0pt,
afterskip=0pt,
]{chapter}
\newmdenv[
skipabove=16pt, % why is this necessary?
leftline=false,
rightline=false,
innerleftmargin=0.5mm,
innerrightmargin=0.5mm,
innertopmargin=4pt,
innerbottommargin=1pt,
linewidth=.6pt,
]{chapterframe}
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\begin{chapterframe}%
\raggedchapter%
\@hangfrom{\vphantom(#2}{#3}%
\end{chapterframe}%
\nointerlineskip}
\widowpenalty10000
\clubpenalty10000
\begin{document}
\flushbottom
\chapter{Foo}
\lipsum[1-4]
\chapter{Bar}
\lipsum[1-4]
% just the right amount of text to cause paragraph spacing to stretch
Fusce mauris. Vestibulum luctus nibh at lectus. Sed
bibendum, nulla a faucibus semper, leo velit ultricies
tellus, ac venenatis arcu wisi vel nisl. Vestibulum
diam. Aliquampellentesque, augue quis sagittis posuere,
turpis lacus congue quam, in hendrerit risus eros eget
felis.
\end{document}
I get the following two issues:
- I need to define a skip so that the upper line of the title does not go outside the text box. This would seem to indicate, that the
beforeskipin\RedeclareSectionCommanddoes not result in a zero skip, but a negative skip. - When paragraph spacing is stretched to prevent orphans/widows, the position of the chapter title relative to the page changes, as apparently the negative space is not only present but "stretchy".
Therefore my question is the following: Why is there a negative space and how can I remove it or at the very least prevent it from stretching so that the chapter title remains at a fixed position?
After some experimenting, the following appears to solve the issue, but I'd still like to know the cause (neater solutions are welcome too!):
\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
\makebox[.65\linewidth][l]{%
\begin{minipage}{\linewidth}%
\vspace{1.6pt}
\begin{chapterframe}%
\raggedchapter%
\@hangfrom{\vphantom(#2}{#3}%
\end{chapterframe}%
\end{minipage}%
}}
The \makebox is needed to avoid the original overfull hbox issue, and the minipage appears to solve the spacing issue. There is still a minor negative, but apparently constant, vspace of 1.6pt. This may or may not be the sum of the line width and the inner bottom margin.
\showboxdepthI hadn't heard of that before. – Joe Feb 23 '19 at 17:44minipageenvironment inside of a narrower\makebox(otherwise I get the original overfull hbox issue). This still seems to cause a small negative space, but it seems to be constant and only about 1.6pt (or maybe it seems constant because it's so small, who knows). I'd still like to know the cause for the issue though. – Joe Feb 23 '19 at 17:45\parskipwithout needing to use the explicit group, but this works and is hopefully all the pointer someone who knows the koma script (and/or mdframed) code to trace where this stretch space is coming from needs. So you may get another answer ... – David Carlisle Feb 23 '19 at 18:40