[Tex/LaTex] mdframed missing half the frame

mdframed

Any obvious reason some of the frame is missing here:

enter image description here

\documentclass{article}

\usepackage{color}
\usepackage{hyperref}
\usepackage{mdframed}
\begin{document}

\begin{mdframed}
\begin{enumerate}
   \item Create the cumulative sum of probabilities for each care type, thus defining the interval width
   \item \textcolor{blue}{for} jj=1:m \textcolor{gray}{\% where m is the number of nurses}
   \item Choose care type
   \item \hspace{3cm}Randomly select care length ($n$) based on care type
     \item \item \textcolor{blue}{for} ii=1:n  \textcolor{gray}{\% where n is the sequence length}
   \item\hspace{3cm}Generate a random number $w$
  \item \hspace{3cm}Check into which cumulative probability interval $w$ falls and choose the corresponding surface category
  \item update ii=ii+1
  \item update jj=i+1
  \item \textcolor{blue}{end}
  \item \textcolor{blue}{end}
\end{enumerate}%}
\end{mdframed}

\end{document}

Best Answer

Analysis

If package color is loaded a white background is drawn. The default framemethod uses the following z-order similar to \fcolorbox:

  1. left line
  2. top line
  3. background
  4. bottom line
  5. right line

Screens have usually a low resolution, thin lines can then have a line width of one pixel only. In the direct neighborhood the white background is drawn. Then it can happen that the white background also colors the pixels of the formerly black line, a part of the black line might contain to the background area (low resolution!, rounding issues, ...).

Printers are using higher resolutions, e.g. 600 dpi. Then a line with thickness of 0.4pt (default value). That are 3.3 pixels, when printed. Then the line will not vanish, if the thickness is one pixel short.

Test file

Test file for playing and analyzing:

  • It makes a simple page with a frame. Fonts are not needed to keep the PDF file small.
  • The page layout is simplified via package geometry.
  • Unit is bp, the default unit for PDF (and PS). This makes it easier to understand and interpret the numbers found in the page description of the PDF file.
  • PDF compressions are disabled (pdflatex). Then the PDF file can be easily inspected in a text viewer or editor.
\pdfobjcompresslevel=0
\pdfcompresslevel=0

\documentclass{article}
\usepackage[
  margin=0pt,
  hmargin=10bp,
  paperwidth=100bp,
  paperheight=50bp,
]{geometry}
\setlength{\topskip}{0bp}
\pagestyle{empty}

\usepackage{xcolor}
\usepackage{mdframed}

\mdfsetup{
  linewidth=.2bp,
  innerleftmargin=0bp,
  innerrightmargin=0bp,
  innertopmargin=0bp,
  innerbottommargin=0bp,
}

\begin{document}
\vspace*{10bp}
\begin{mdframed}
\rule{0pt}{10bp}
\end{mdframed}
\end{document}

Workaround

Package mdframed provides other framemethods. With

\usepackage[framemethod=tikz]{mdframed}

the frame is drawn after the background and therefore remains visible.