T-F-S / tcolorbox

A LaTeX package to create highly customizable colored boxes.
http://www.ctan.org/pkg/tcolorbox
LaTeX Project Public License v1.3c
213 stars 15 forks source link

A title rule of zero width may still be visible #266

Open dbitouze opened 5 months ago

dbitouze commented 5 months ago

As shown by the following MCE, a title rule of zero width may still be visible (depending on the PDF viewer and/or the zoom):

\documentclass{article}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[
  , title={Foo}
  , colbacktitle=white
  , colback=white
  , coltitle=black
  , titlerule = 0mm
  ]
  Bar
\end{tcolorbox}
\end{document}

image

muzimuzhi commented 5 months ago

To overcome some of the PDF viewer's "smart" behaviors, apart from usual tricks like detaching then reinserting title and emulating frame by /tcb/borderline, it's also possible to fill the title and interior as a whole, by setting a customized /tcb/interior titled code.

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{breakable, magazine, skins}

\makeatletter
\tcbset{
, notitlerule unbroken/.style={
  , title empty
  , interior titled code={
      % fill title with color /tcb/colback too
      \fill[tcbcolback]
        [rounded corners=\kvtcb@arc]
          (title.north west) rectangle (interior.south east);
    }
  }
, notitlerule first/.style={
  , title empty
  , interior titled code={
      \fill[tcbcolback]
        [rounded corners=\kvtcb@arc]
          ([yshift=-\kvtcb@bottom@rule@break]interior.south west)
          -- (title.north west) -- (title.north east)
        [sharp corners]
          -- ([yshift=-\kvtcb@bottom@rule@break]interior.south east)
          -- cycle;
    }
  }
, notitlerule/.style={
  , extras unbroken={notitlerule unbroken},
  , extras first={notitlerule first}
  }
}
\makeatother

\tcbset{titlerule=0pt, coltitle=black, fonttitle=\bfseries}

\begin{document}

\begin{tcolorbox}[
  , enhanced
  , notitlerule
  , title=Unbreakable
]
  No title.
\end{tcolorbox}

\begin{tcolorbox}[
  , enhanced
  , breakable
  , notitlerule
  , title={Breakable but unbroken}
]
  Bar
\end{tcolorbox}

\begin{tcolorbox}[
  , enhanced
  , breakable
  , break at=2cm
  , notitlerule
  , title={Breakable and broken}
  , reset box array
  , store to box array
]
  Bar \par
  Bar \par
  Bar \par
  Bar \par
  Bar \par
  Bar \par
\end{tcolorbox}

\noindent
\useboxarray{1}\\[.5\baselineskip]
\useboxarray{2}\\[.5\baselineskip]
\useboxarray{3}

\end{document}
image

Compatibilities with /tcb/title after break and/or jigsaw skins are not handled (yet). Eventually, it seems a new set of skins are required.

T-F-S commented 5 months ago

@dbitouze The previewer glitch to show zero rule lines is known for a very long time. It is depended from the used skin which have different drawing philosophies.

grafik

\documentclass{article}
\usepackage[skins]{tcolorbox}
\begin{document}

Box with previewer glitch:

\begin{tcolorbox}[
  , title={Foo}
  , colbacktitle=yellow
  , colback=yellow
  , coltitle=black
  , titlerule = 0mm
  ]
  Bar
\end{tcolorbox}

Box with previewer glitch (frame only):

\begin{tcolorbox}[
  , title={Foo}
  , colbacktitle=yellow
  , colback=yellow
  , coltitle=black
  , titlerule = 0mm
  , interior titled engine=empty
  , title engine=empty
  ]
  Bar
\end{tcolorbox}

Box without (visible) previewer glitch:

\begin{tcolorbox}[
  standard jigsaw,
  , title={Foo}
  , colbacktitle=yellow
  , colback=yellow
  , coltitle=black
  , titlerule = 0mm
  ]
  Bar
\end{tcolorbox}

Box without (visible) previewer glitch (frame only):

\begin{tcolorbox}[
  standard jigsaw,
  , title={Foo}
  , colbacktitle=yellow
  , colback=yellow
  , coltitle=black
  , titlerule = 0mm
  , interior titled engine=empty
  , title engine=empty
  ]
  Bar
\end{tcolorbox}

\end{document}
dbitouze commented 5 months ago

@T-F-S Maybe it is worth to add a warning in the documentation where titlerule is defined.

dbitouze commented 1 month ago

The last box below shows just the frame. The third box does not show the zero line. In truth: depending on the previewer, it does, but a zero width white line between white (or very bright boxes) is not show in my previewer...

Indeed, with Okular on GNU/Linux, the zero width line is still visible.