1

I am using \tcbsubtitle to place a title at the top of a tcblower and want a different background color on the two portions. This results in an unwated space above the subtitle:

enter image description here

How do I eliminate this undesired space?

References:

Code:

\documentclass{article}

\usepackage[many]{tcolorbox}

\newcommand{\LoremIpsum}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.%
}

\tcbset{My Box Style/.style={
    colback=green!20,
    bicolor,  
    colbacklower=yellow!60,
    %segmentation at break=false,% No effect
    %middle=0pt,% <-- This isn't it!
}}

\newtcolorbox{example}{My Box Style}

\begin{document}
\begin{example}
    \LoremIpsum
    \tcblower
    \tcbsubtitle{Subtitle}
    \LoremIpsum
\end{example}
\end{document}
2
  • I think that this is the similar post that I remembered seeing earlier: tex.stackexchange.com/questions/414537/…
    – user30471
    Commented Jun 27, 2020 at 14:04
  • @Andrew: Good find. I wasn't able to locate it. Thanks. Am voting to close as a duplicate. Commented Jun 27, 2020 at 21:54

1 Answer 1

2

Second attempt It seems to be controlled by middle and boxsep. If we set them both to be zero the we get:

enter image description here

It's not immediately clear to me that this is better than the previous manual adjustment. First, there is a faint hint of a yellow line above the subtitle line. Secondly, as explained on page 11 of the manual, boxsep is added all over the place, which is why this kills off the space at the bottom of the green box and the height of the subtitle.

\documentclass{article}

\usepackage[many]{tcolorbox}

\newcommand{\LoremIpsum}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.%
}

\tcbset{My Box Style/.style={
    colback=green!20,
    bicolor,
    colbacklower=yellow!60,
    middle=0mm,
    boxsep=0mm,
    subtitle style={}
    %segmentation at break=false,% No effect
    %middle=0pt,% <-- This isn't it!
}}

\newtcolorbox{example}{My Box Style}

\begin{document}
\begin{example}
    \LoremIpsum
    \tcblower
    \tcbsubtitle{Subtitle}
    \LoremIpsum
\end{example}
\end{document}

First attempt

I have a feeling that I have seen this before but I cannot find it.

The \tcbsubtitle command actually inserts a new tcolorbox that contains the subtitle, so I suspect that this gap is caused by some skip above this box. There should be some way to remove this but I have not found it.

The following hack adds a manual \vspace command above the subtitle, but there should be a better solution:

\documentclass{article}

\usepackage[many]{tcolorbox}

\newcommand{\LoremIpsum}{%
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.%
}

\tcbset{My Box Style/.style={
    colback=green!20,
    bicolor,
    colbacklower=yellow!60,
    subtitle style={before={\vspace*{-3.1mm}}}
    %segmentation at break=false,% No effect
    %middle=0pt,% <-- This isn't it!
}}

\newtcolorbox{example}{My Box Style}

\begin{document}
\begin{example}
    \LoremIpsum
    \tcblower
    \tcbsubtitle{Subtitle}
    \LoremIpsum
\end{example}
\end{document}

Here is the output:

enter image description here

You could also use \tcbsubtitle[before={\vspace*{-3.1mm}}]{Subtitle}, but using the style command seems more elegant.

2
  • Seems to work, but had to change the amount for my particular use case. There must be an exact amount or some setting for this, but this is a great workaround until then. Thanks. Commented Jun 27, 2020 at 2:10
  • 1
    @PeterGrill Even into a normal tcolorbox a tcbsubtitle leaves some space on top of it. I think it's \top+\boxsep plus some other value that I cannot relate with geometry settings.
    – Ignasi
    Commented Jun 27, 2020 at 8:39

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