Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic number yshift=0.1mm in bicolor skin #166

Closed
muzimuzhi opened this issue Jan 8, 2022 · 5 comments
Closed

Magic number yshift=0.1mm in bicolor skin #166

muzimuzhi opened this issue Jan 8, 2022 · 5 comments
Assignees

Comments

@muzimuzhi
Copy link
Contributor

With skin=bicolor, the lower part is filled with a possibly different color. But the top of that filling is 0.1mm higher than the y-coord of segmentation node. Since 0.1mm ~= 0.28pt is comparable to the default line with 0.4pt, this shifting is noticeable in certain use cases, for example the one in https://tex.stackexchange.com/q/628634 as noticed by @dbitouze .

The introduce of such magic number dates back to v3.0.5 and I suspect it is used to prevent the "thin white line" issue when upper and lower parts are filled with the same color (with skin=bicolor).

Multiple workarounds/improvements exist:

  • use a smaller length, e.g., .01mm
  • make it configurable (ugly)
  • if what I suspect is close to the truth, then the better way, instead of setting a magic number, would be to compute a "distance" between the two filling colors and when they're too close, degenerate to normal skin (fill the colored box in a whole) and raise a warning.

Related code lines

\def\tcb@drawspec@LR#1{%
\tcb@pathbase{#1,segmentation@style}{interior.south west}{[yshift=0.1mm]segmentation.east}%
{\tcb@arc@ins@SW}{\tcb@arc@zpt}{\tcb@arc@zpt}{\tcb@arc@ins@SE}%
}
\def\tcb@drawspec@LS#1{%
\tcb@pathbase{#1,segmentation@style}{interior.west|-frame.south}{[yshift=0.1mm]segmentation.east}%
{\tcb@arc@zpt}{\tcb@arc@zpt}{\tcb@arc@zpt}{\tcb@arc@zpt}%
}

@T-F-S
Copy link
Owner

T-F-S commented Jan 10, 2022

Yes, it is connected to thin white line issue. As far as I remember

  • a smaller length leads to visible lines depending on PDF viewers. In theory, no overlap is needed. In theory, a very small overlap is needed, if the first theory does not meet practice. Unfortunately, a considerable overlap is needed (or was needed in my tests a few years ago). If 0.1mm is considered considerable, here.

  • The white line glitch also appears, if colors are different (as far as I remember) and there is no overlap.

@muzimuzhi
Copy link
Contributor Author

Sorry I forgot to provide a link to "thin white line" example (also the ones linked to this question on tex-sx). According to feedbacks on tex-sx (1 and 2), it seems .1pt is enough.

Imho the specific small shifting amount is not cared about until users add some visual benchmark. In this case, either canceling the shifting (by providing a new option) or making the shifting amount accessible (so user drawings can be around a fake segmentation y-coord) would help.

@dbitouze
Copy link
Contributor

For what it is worth, here is an example of the need to deal with the magic number yshift=0.1mm in bicolor skin. The glitch is visible even with not so large zoom values:

\documentclass{article}
\usepackage{tcolorbox}

\tcbuselibrary{listings,skins}

\begin{document}
\begin{tcblisting}{%
    sharp corners,
    skin=bicolor,
    top=0.5cm,
    middle=0.5cm,
    overlay={
      \node[minimum width=1cm,minimum height=0.5cm,outer sep=auto,
      anchor=north east,fill=white] at (interior.north east)
      {\itshape\small code};
      \node[minimum width=1cm,minimum height=0.5cm,outer sep=auto,
      anchor=north east,fill=white] at (% [yshift=.1mm]
      segmentation.east)
      {\itshape\small result};
    }
  }
Foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foooo
foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foooo
\end{tcblisting}
\end{document}

image

@T-F-S T-F-S self-assigned this Jan 11, 2022
@T-F-S
Copy link
Owner

T-F-S commented Jan 11, 2022

I will add configuration of the magic number as new feature:

This allows the following:

\documentclass{article}
\usepackage{tcolorbox}

\tcbuselibrary{listings,skins}

\begin{document}

\begin{tcolorbox}[bicolor, sharp corners,
    colframe=blue!50!black, colback=blue!10, colbacklower=red!10,
    top=5mm, bottom=2mm, middle=3.5mm, overlaplower=1.5mm,
    underlay={
      \node[minimum width=1cm,minimum height=0.5cm,outer sep=auto,
        anchor=north east,fill=white] at (interior.north east)
        {\itshape\small upper};
      \node[minimum width=1cm,minimum height=0.5cm,outer sep=auto,
        anchor=north east,fill=white]
        at ([yshift=\tcboverlaplower]segmentation.east)
        {\itshape\small lower};
    }
  ]
This is the upper part.
\tcblower
And that is the lower part.
\end{tcolorbox}
\end{document}

grafik

@T-F-S
Copy link
Owner

T-F-S commented Jun 22, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants