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.


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


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.

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




% draw a line grid
   \foreach \y in {0,...,-42}
      \draw [magenta] (0,\y*\baselineskip) -- ++(\textwidth,0);
   Without descender it works.
   But with descenders the skip is a little too much.

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


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


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


  • @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

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

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

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.

  • 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

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.