Analysis
If package color
is loaded a white background is drawn. The default framemethod
uses the following z-order similar to \fcolorbox
:
- left line
- top line
- background
- bottom line
- 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.
With tcolorbox
most of the requests can be done out of the box. Most important is minipage boxed title=0.8\linewidth
, for example.
\documentclass[11pt]{book}
\usepackage{amsthm}
\usepackage[utf8]{inputenc}
\usepackage[usenames,dvipsnames,table]{xcolor}
\usepackage{tikz}
\usepackage[framemethod=TikZ]{mdframed}
\mdfsetup{skipabove=\topskip,skipbelow=\topskip}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of the theorem environment %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{theo}[chapter]\setcounter{theo}{0}
\renewcommand{\thetheo}{\arabic{chapter}.\arabic{theo}}
\makeatletter
\newenvironment{teorema}[1][]{%
\refstepcounter{theo}%
%\stepcounter{theo}\protected@edef\@currentlabel{\thetheo}%
\ifstrempty{#1}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double= Violet!50]
{\strut Teorema~\thetheo};}}
}%
{\mdfsetup{%
frametitle={%
\tikz[baseline=(current bounding box.east),outer sep=0pt]
\node[anchor=east,rectangle,rounded corners,fill=Violet!20,draw= Violet!50, double=Violet!50]
{\strut Teorema~\thetheo:~#1};}}%
}%
\mdfsetup{innertopmargin=10pt,linecolor=Violet!50,backgroundcolor=Violet!5,%
linewidth=2pt,topline=true,
frametitleaboveskip=\dimexpr-\ht\strutbox\relax,roundcorner=10pt}
\begin{mdframed}[]\relax%
\vspace{-0.25cm}}{\qed\end{mdframed}}
\makeatother
\usepackage[most]{tcolorbox}
\usepackage{blindtext}
\newtcbtheorem[auto counter,number within=chapter]{teoremaother}{Teorema}{%
boxrule=2pt,
enhanced,
colback=Violet!5,
colframe=Violet!50,
colbacktitle=Violet!20,
coltitle=black,
fonttitle={\bfseries},
minipage boxed title=0.8\linewidth,
attach boxed title to top left={xshift=10pt,yshift*={-\tcboxedtitleheight/2}},
boxed title style={parbox,boxrule=2pt},
after upper={\qed},
}{th}
\begin{document}
\chapter{Sample Chapter}
\begin{teorema}[The theorem's statement which is a very long, long, long, long text]
Its proof
\end{teorema}
\begin{teoremaother}{The theorem's statement which is a very long, long, long, long text}{}
Its proof
\end{teoremaother}
\begin{teoremaother}{\blindtext}{}
Its proof
\end{teoremaother}
\end{document}
Best Answer
Update
The version 1.2 of mdframed has new possibilities for setting the frame title. Based of your request you can simple use the option
frametitlerule=true
andframetitlebackgroundcolor=gray!20
. The current version is available at github.By using
tikz
to modify the header here one suggestion.You have to modify the command
\mdframetitleenv
to influence the output. The package itself controls whether the frame title is empty or not.