2

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.

sample document

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)
3
  • Which pdf viewer do you use? I do not see any white lines.
    – yannisl
    Commented Apr 23, 2012 at 2:07
  • @YiannisLazarides: evince, okular and zathura on Linux. With acroread I do not see the thin white lines.
    – Romildo
    Commented Apr 23, 2012 at 2:10
  • 1
    It is a problem with the viewer and not the code.
    – yannisl
    Commented Apr 23, 2012 at 5:05

1 Answer 1

4

This is most likely a feature of the viewer, however you can workaround it by inserting a small negative skip (the smallest fraction of a point that works on your screen) so that the coloured boxes overlap. Depending on your requirements that may be enough or you may want to compensate by increasing the height of the box so

instead of

    \colorbox{yellow}{\box\boxhead}%

something like

     \vskip-0.1pt
     \colorbox{yellow}{\advance\ht\boxhead0.1pt\box\boxhead}%

You must log in to answer this question.

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