3

How can I correct the transition between the background-colors? The MWE:

\documentclass[a4paper]{article}
\usepackage[scale=.85]{geometry}
\usepackage{tcolorbox,enumitem}
\tcbuselibrary{skins,xparse}

\begin{document}
\noindent

\begin{tcolorbox}[skin=bicolor,title=Main Title,
    colframe=red!75!black,colback=blue!10!white,colbacklower=green!10,width=0.5\linewidth,height=0.5\linewidth]
    The upper part. \par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~
\tcblower
\tcbsubtitle[before skip=\baselineskip]%
      {My subtitle}
    The lower part.
  \end{tcolorbox}


\end{document}

and the result is:

enter image description here

Thanks a lot; Harald

3

This is really wierd and is probably a bug. The hack in the code below fixes the problem to produce:

enter image description here

but I don't understand what is happening. The before skip=... is supposed to take care of this but adjusting the skip amount alone does not fix the problem. Similarly, it should be possible to do this using only a \vskip command but I could not get this to work either. I was only able to fix the problem by having both a \vskip and a before skip. Here's the hack:

\documentclass[a4paper]{article}
\usepackage[scale=.85]{geometry}
\usepackage{tcolorbox,enumitem}
\tcbuselibrary{skins,xparse}

\begin{document}
\noindent

\begin{tcolorbox}[skin=bicolor,title=Main Title,
    colframe=red!75!black,colback=blue!10!white,colbacklower=green!10,
    width=0.5\linewidth,
    height=0.5\linewidth]
    The upper part. \par ~~~\par ~~~\par ~~~\par 
    ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~
\tcblower\vskip-\baselineskip
\tcbsubtitle[before skip=-\baselineskip]{My subtitle}
    The lower part.
  \end{tcolorbox}

\end{document}

You may need to adjust the \vskip amount as I think that -\baselineskip puts the subtitle a fraction too high, but using this was more asthetically pleasing than choosing a random distance.

  • 1
    interesting ... your solution also work with \tcblower\vskip0pt :-) – Zarko Feb 9 '18 at 21:45
  • @Zarko Thanks, I'd hadn't noticed this. There must be funny skips in the tcolorbox code, but I haven't looked. – Andrew Feb 9 '18 at 22:54
  • @Andrew, it seems that this skip somehow anchor \tcblower. why, i don't know either. in come cases i observe that it behavior as strut, but i'm not programmer (and may be wrong) ... – Zarko Feb 9 '18 at 23:04
  • I've reported this as an issue with tcolorbox at github.com/T-F-S/tcolorbox/issues/36 – Andrew Feb 9 '18 at 23:07
4

Deliberately, there is some distance between the separation line and the content of the lower box part. Adding the draft options helps to understand what happens:

\documentclass[a4paper]{article}
\usepackage[scale=.85]{geometry}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}

\begin{document}

\begin{tcolorbox}[skin=bicolor,draft,title=Main Title,
    colframe=red!75!black,colback=blue!10!white,colbacklower=green!10,width=0.5\linewidth,height=0.5\linewidth]
    The upper part. \par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~
\tcblower
\tcbsubtitle[]%
      {My subtitle}
    The lower part.
\end{tcolorbox}

\end{document}

enter image description here

The distance between the bicolor separation line and the content of the lower part is middle (default: 2mm) plus boxsep (default: 1mm). You see these distances in white and pink color.

The subtitle starts exactly at the begin of the lower part (you may spot the dashed line at the top of the subtitle).

To move the subtitle upwards to the separation line, one could use enlarge top initially by to change the bounding box of the subtitle. This works as long as the height of the subtitle is larger than the corrected distance. Actually, I would add a small additional distance to avoid optical glitches when two lines are matched, e.g. use 3.1mm for the default values:

\documentclass[a4paper]{article}
\usepackage[scale=.85]{geometry}
\usepackage{tcolorbox}
\tcbuselibrary{skins,xparse}

\begin{document}

\begin{tcolorbox}[skin=bicolor,title=Main Title,
    colframe=red!75!black,colback=blue!10!white,colbacklower=green!10,width=0.5\linewidth,height=0.5\linewidth]
    The upper part. \par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~\par ~~~
\tcblower
\tcbsubtitle[enlarge top initially by=-3.1mm]% -(middle+boxsep+tinydelta)
      {My subtitle}
    The lower part.
\end{tcolorbox}


\end{document}

This gives:

enter image description here

  • Thank you very much for your hint and for the "background" information – Harald Feb 14 '18 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.