Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

When using the mdframed environment with absolutely tight margins (all set 0pt), there is too much negative vertical space of split md-frames that are placed at the top of a page.

To illustrate this, the minimal working example creates two text pages, the second of which contains text in an md-frame, clearly not aligned with the text in the first page.

I created the example using a command \FOO, which calls an environment valignFOO that contains the actual mdframed environment named mdframedFOO, the latter of which has margin sizes of zero and a small frame for visual reference.

valignFOO is responsible for Making mdframed paragraph behave like normal paragraphs in terms of spacing. But even by using that improvement with respect to vertical spacing, I still observe extra space as described above.

\documentclass[12pt,a6paper]{scrbook}

\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

% New mdframed environment called mdframedFOO:
\newmdenv[leftmargin        = 0pt,
          rightmargin       = 0pt,
          innerleftmargin   = 0pt,
          innerrightmargin  = 0pt,
          innertopmargin    = 0pt,
          innerbottommargin = 0pt,
          skipabove         = 0pt,
          skipbelow         = 0pt,
          splittopskip      = 0pt,
          splitbottomskip   = 0pt,
          outerlinewidth    = 1pt,
          middlelinewidth   = 0pt,
          innerlinewidth    = 0pt,
          topline           = false,
          bottomline        = false
         ]{mdframedFOO}

% Correct vertical alignment of mdframedFOO:
% (This is for making mdframed behave like a normal paragraph,
%  see http://tex.stackexchange.com/questions/88525/making-mdframed-paragraph-behave-like-normal-paragraphs-in-terms-of-spacing)
\newenvironment{valignFOO}
 {\par\vskip\dimexpr\dp\strutbox-\prevdepth\relax\mdframedFOO\strut\ignorespaces}
 {\par\xdef\notetpd{\the\prevdepth}\endmdframedFOO\vskip-\notetpd\relax}

% FOO:
\newcommand{\FOO}[1]{%
  \begin{valignFOO}
    #1
  \end{valignFOO}
}




\begin{document}
  \lipsum[2]
  \FOO{\lipsum[2]}
\end{document}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.