5

I am trying to write a LaTeX document involving a lot of definitions. For this reason, I decided to create a mdframed environment (see below), and place my definitions one after the other in a two-column environment.

\newmdenv[%
    frametitleaboveskip=5pt, frametitlebelowskip=5pt,
    backgroundcolor=white,frametitlerule=true,
    frametitlebackgroundcolor=black!20,linewidth=1pt,
    frametitlefont=\ttfamily
]{numframed}

Basically, this gives me a simple titled box, with a gray header, and a white background for the definition itself. However, I noticed that the height of my gray headers varies. This is particularly annoying when the second column receives its first definition:

\begin{multicols*}{2}
    \begin{numframed}[frametitle=Text with letters going below line]
    \end{numframed}

    % ... other definitions until the end of the first column

    \begin{numframed}[frametitle=Text without these letters]
    \end{numframed}
\end{multicols*}

mdframed titles with irregular height

As you can see, in the first column, the first definition's title contains letters which go "below the line" : the g's. There is no such letter in the first definition of the second column. In each case, LaTeX naturally fits the container to the content.

Now, having these two boxes, one next to the other, and getting misaligned title headers really annoys me. Would there be a way for me to fix the title header's height (and possibly set vertical alignment to center afterwards) in order to align my header areas completely?

  • Did you try minimum height=1.5em for example? – Sigur Feb 23 '15 at 15:50
  • @Sigur It does not appear to be a valid parameter when defining an environment (titledframe). Wouldn't it apply to the entire box instead of just the title? I've never manipulated TikZ parameters before. – John WH Smith Feb 23 '15 at 15:59
  • 3
    Add a \strut to the title,as in frametitle={\strut The title text\strut}. I'm writing an answer in which this is done automatically. – Gonzalo Medina Feb 23 '15 at 16:05
2

One option using \strut for the title:

\documentclass{article}
\usepackage{mdframed}
\usepackage{multicol}
\usepackage{xcolor}

\newmdenv[%
    frametitleaboveskip=5pt, frametitlebelowskip=5pt,
    backgroundcolor=white,frametitlerule=true,
    frametitlebackgroundcolor=black!20,linewidth=1pt,
    frametitlefont=\ttfamily,
    ]{numframedi}
\newenvironment{numframed}[2][]
  {\begin{numframedi}[#1,frametitle={\strut#2\strut}]}
  {\end{numframedi}}    

\begin{document}

\begin{multicols}{2}
    \begin{numframed}{Text with descenders py}
    \end{numframed}
    \begin{numframed}{Text with no descenders in two lines}
    \end{numframed}
    \begin{numframed}{Text with no descenders}
    \end{numframed}
    \begin{numframed}{Text with descenders in two lines py}
    \end{numframed}
\end{multicols}

\end{document}

enter image description here

The new syntax for numframed is

\begin{numframed}[<options to mdframed>]{<title>}
(...contents...)
\end{numframed}
  • Works like a charm :) I simplified it a little by removing the options passed to mdframed by numframed, since they will not be necessary in my document. – John WH Smith Feb 23 '15 at 16:22

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.