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.

How can we make mdframed to ignore the descenders of the last line in the calculation of the innerbottomsep. In my eyes there are two reasons to desire this:

Inner margin
The optical bottom sep is too large in a line that contains descenders compared with on the has none.

margins

Line grid
It is impossible to keep in the line grid, which otherwise could be achieved by adjusting the skip above and below.

grid

As the image shows the frame without descenders keeps the following lines in the grid with the well adjusted skips but if we got descenders the adjustment is broken.

Code
This is the code I used to produce the images (comment out on line to get the first image).

\documentclass{scrartcl}

\usepackage{tikz}
\usepackage{mdframed}

\newmdenv[%
   skipabove=12.6pt,
   skipbelow=12.6pt,
]{myframe}

\usepackage{lipsum}
\begin{document}
% draw a line grid
\noindent
\begin{tikzpicture}[overlay]
   \foreach \y in {0,...,-42}
      \draw [magenta] (0,\y*\baselineskip) -- ++(\textwidth,0);
\end{tikzpicture}%
\lipsum[1]
\begin{myframe}
   Without descender it works.
\end{myframe}
\lipsum[2]
\begin{myframe}
   But with descenders the skip is a little too much.
\end{myframe}
\lipsum
\end{document}
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can get a consistent space below the line by forcing a baselineskip to be inserted like this:

\par\strut\par
\unskip\unskip\setbox0=\lastbox

This way, a 'pseudo-line' is inserted and then removed, leaving exactly the amount of space which would fill up the baseline distance. And this of course depends on whether there are descenders or not.

Unfortunately, it seems mdframed is removing trailing vertical space, so normally, the additional space would vanish again. In addition, you'd always get the spacing of the latter example, which doesn't seem to be what you want. You can counteract both by adding

\vspace*{\dimexpr\ht\strutbox-\baselineskip\relax}

which adds negative vertical space corresponding to the distance between the baseline and the beginning of the next line.

Of course, this can be put together as a new environment, leading to the solution

\newmdenv[%
   skipabove=12.6pt,
   skipbelow=12.6pt,
]{@myframe}

\newenvironment{myframe}
{%
  \begin{@myframe}
}
{ 
  \par\strut\par
  \unskip\unskip\setbox0=\lastbox
  \vspace*{\dimexpr\ht\strutbox-\baselineskip\relax}
  \end{@myframe}
}
share|improve this answer
    
Works fine. Thanks :-) –  Tobi Apr 11 '12 at 12:59
    
@Tobi: I added the option ignorelastdescenders to the new version at gihub. at:Stefan thanks for the great solution. –  Marco Daniel May 18 '12 at 11:46
    
@MarcoDaniel: Thanks! –  Tobi May 21 '12 at 7:37
add comment

You can enclose your text in a vbox and adjust according to your taste.

\begin{myframe}
   \vbox to 0pt {But with descenders the skip is a little too much.}
\end{myframe}

You can change the vbox to 0pt to another length to suit (5.5pt looks right for me). For more control you can even enclose a strut in the \vbox. Use a:

vrule height..pt width0pt depth..pt

for more control.

share|improve this answer
    
Thanks but I desire a more automatic solution since it would be much work to create a \vbox for about 100 frames manually … –  Tobi Mar 11 '12 at 10:12
    
@Tobi Then I suggest you capture the contents, place them in a box and check if the box has depth (this will signal that there are descenders), then adjust accordingly. –  Yiannis Lazarides Mar 11 '12 at 10:52
    
If I'm understanding this correctly, stuff in the myframe environment would break over pages. This property is lost by enclosing the content in a \vbox. –  Stephan Lehmke Apr 10 '12 at 14:39
    
@StephanLehmke: Yes thats right … –  Tobi Apr 10 '12 at 21:27
add comment

Your Answer

 
discard

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

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