The purpose of the mybox
environment in the following document is to
typeset a box in a blue background. The box may be split by page
breaks. The algorithm used is similar to the one found in the boites
package:
- first the text is formatted in a vbox
- then each line of the vbox is extracted from the vbox and output in a colorbox.
The document:
\documentclass{article}
\usepackage[paperwidth=10cm,paperheight=35mm,margin=3mm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{lipsum}
\pagestyle{empty}
\newbox\boxhead
\newbox\boxtail
\newbox\boxtemp
\newdimen\dimtemp
\def\boxsplit{%
% total height of original box
\dimtemp\ht\boxtail
\advance\dimtemp\dp\boxtail
% split original box in order to retrieve its first line
\setbox\boxhead\vsplit\boxtail to 0pt
% fix the height of the first line
\setbox\boxhead\vbox{\unvbox\boxhead}%
% restore original size
\setbox\boxtemp\vbox{\copy\boxhead\copy\boxtail}%
\advance\dimtemp-\ht\boxtemp
\advance\dimtemp-\dp\boxtemp
\advance\dimtemp\dp\boxhead
\dp\boxhead\dimtemp
}
\newenvironment{mybox}{%
\ifhmode\par\fi
\setbox\boxtail\vbox\bgroup
}{%
\egroup
{%
\noindent
\fboxsep 0pt
\splittopskip 0pt
\baselineskip 0pt
\lineskiplimit 0pt
\lineskip 0pt
\vfuzz\maxdimen
\leavevmode
\loop
\ifvoid\boxtail
\else
\boxsplit
\colorbox{blue}{\hbox to \linewidth{\box\boxhead}\hfil}%
\hfil
\repeat
}%
}
\begin{document}
\begin{mybox}
\lipsum[68]
\end{mybox}
\end{document}
When looking with care (the following image shows the document opened in the evince
pdf viewer), very thin white rules can be seen between the
blue lines in the text formatted by the environment.
Has anybody any clues on how to eliminate them?
I know there are packages like mdframed
that already provides this functionality using a different algorithm. But they do not work with the beamer
class or in multicolumn environments, and they cannot be nested.
EDIT:
As pointed by others, this seems to be an issue with the pdf viewer. I tried several viewers (on Linux) and found that some of them shows the thin white rules and others do not.
Good pdf viewers:
- qpdfview 0.4.9
- adobe reader 9.5.5
- okular 0.18.3
- foxit reader 6.1.4.0217 (with wine)
Bad pdf viewers:
- evince 3.10.3
- epdfviewer 0.1.8
- sumatra pdf 2.4 (with wine)
- pdf-xchange (with wine)