1

I use mdframed to create a black background in a preview environment. Since I could not figure out how to color the preview border black as well, I set it to 0 and included a black line around the content with mdframed. Unfortunately there are small white lines between the mdframed background and the mdframed outer line.

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[active,tightpage]{preview}
\renewcommand{\PreviewBorder}{0cm}
\usepackage{mdframed}
\usepackage{lipsum}

\begin{document}
\begin{preview}
\begin{mdframed}[backgroundcolor=black,fontcolor=white,linecolor=black,linewidth=0.5cm]

\section{Title}
\lipsum[10]

\end{mdframed}
\end{preview}
\end{document}

Is there a way to get rid of them? Alternatively, if there is a way to change the color of the preview border, I could circumvent the problem entirely. Thanks in advance for your help :)

5
  • 1
    use tcolorbox instead of mdframed. That is much more powerful and stable and it is maintained. Jul 16, 2022 at 11:02
  • I already use tcolorboxes as part of the document. Nesting them screwed everything up even worse than this. Jul 16, 2022 at 11:11
  • 1
    then show something with tcolorbox. mdframed is not much used anymore and you won't find many people willing to debug it. Jul 16, 2022 at 11:20
  • Okay, I'll try that. Jul 16, 2022 at 11:46
  • 1
    The white line you see around the box is a rendering issue of the viewer. If you zoom on the box-edge, the white line goes away. Such "problems" may occur regardless of what package you employ to draw boxes. Jul 16, 2022 at 11:54

1 Answer 1

1

With a {mdframed} within a {mdframed}, you won't have the problem since you only have a black rectangle (instead of 5 rectangles: the main rectangle and 4 rectangles for the border).

\documentclass[12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage[active,tightpage]{preview}
\renewcommand{\PreviewBorder}{0pt}
\usepackage{mdframed}
\usepackage{lipsum}

\begin{document}

\begin{preview}
\begin{mdframed}[backgroundcolor=black,fontcolor=white]

\begin{mdframed}[linewidth=0.5cm]
\section{Title}
\lipsum[10]
\end{mdframed}

\end{mdframed}
\end{preview}
\end{document}

For information, the thin white lines are artefacts of the PDF viewers (the problem is acute with MuPDF used in SumatraPDF and probably even more in PDF.js used by Firefox, DropBox,etc.). However, it's possible to construct PDF files for which the problem never occurs, whatever PDF viewer is used: two contiguous rectangle with the same color must be in the same instruction f in the PDF (f is the PDF operator corresponding to the PostScript operator fill). In the package nicematrix (which I have written), the tabulars with colors are constructed in such a way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .