7

Consider the following mwe:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usetikzlibrary{calc}
\usepackage{lipsum}
\begin{document}
   \begin{tcolorbox}[enhanced,breakable,segmentation code={\draw[red]($(segmentation.west)+(1,0)$)--($(segmentation.east)+(-1,0)$);}]
    test
    \tcblower
    Works as expected
   \end{tcolorbox}

    \begin{tcolorbox}[enhanced,breakable,segmentation code={\draw[red]($(segmentation.west)+(1,0)$)--($(segmentation.east)+(-1,0)$);}]
    \lipsum
    \tcblower
    Does not work as expected
   \end{tcolorbox}
\end{document}

Unbroken box result:

enter image description here

Broken box result:

enter image description here

The goal is to have a tcolorbox with the given segmentation style, e.g. a red line a bit shorter than the box width.

The code works fine if the box does not break, but it seems to be ignored when the box breaks. What am I doing wrong?

Edit: I just discovered than I can force the segmentation code after the break putting it inside a extend freelance last, but this is not a viable solution since it also changes the appearance of the frame in an undesired way.

4
  • See my comments to Gonzalo Medinas answer. Commented May 15, 2014 at 6:11
  • To answer 'What am I doing wrong?': Nothing. segmentation code changes the code of the current skin. That's the unbroken one in your case. For the three broken cases first, middle, last there would be own code definitions. segmentation style changes the style of the whole break sequence. Commented May 15, 2014 at 6:18
  • @ThomasF.Sturm Thanks for the clarification. How do I put my segmentation code into the last or middle part of an enhanced broken box? I know how to do it for freelance, but not for enhanced.
    – d-cmst
    Commented May 15, 2014 at 7:21
  • 1
    Use skin first is subskin of={enhancedfirst}{segmentation code={...}}. The same for middle and last. enhancedfirst can be replaced by any skin, e.g. enhanced if the box should stay closed. A full example is given on page 170 (v3.02). Commented May 15, 2014 at 7:34

1 Answer 1

5

For tcolorbox versions prior to 3.00 (2014/05/08), if you want to use segmentation code you need the freelance key instead of enhanced (in fact, with your original settings, your code doesn't produce the image you showed in the question; the segmentation code option is ignored on both cases if enhanced is used and not freelance):

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usetikzlibrary{calc}
\usepackage{lipsum}
\begin{document}
   \begin{tcolorbox}[freelance,breakable,segmentation code={\draw[red]($(segmentation.west)+(1,0)$)--($(segmentation.east)+(-1,0)$);}]
    test
    \tcblower
    Works as expected
   \end{tcolorbox}

    \begin{tcolorbox}[freelance,breakable,segmentation code={\draw[red]($(segmentation.west)+(1,0)$)--($(segmentation.east)+(-1,0)$);}]
    \lipsum
    \tcblower
    Works as expected
   \end{tcolorbox}
\end{document}

enter image description here

However, using the freelance skin changes the way the box behaves at page breaks, so you would need to redo some parts of the box to get the original behaviour.

Starting from tcolorbox 3.00 (2014/05/08), segmentation code can also be used with enhanced, but I'd suggest using segmentation style instead of segmentation code (this will work in all versions):

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usetikzlibrary{calc}
\usepackage{lipsum}

\newtcolorbox{mybox}{
  enhanced,
  breakable,
  segmentation style={red,solid,shorten >= 1cm,shorten <= 1cm}
}

\begin{document}
   \begin{mybox}
    test
    \tcblower
    Works as expected
   \end{mybox}

    \begin{mybox}
    \lipsum
    \tcblower
    Works as expected
   \end{mybox}

\end{document}

enter image description here

9
  • this also changes the appearance of the frame: with the enhanced skin the frame is not closed when the breaks occurs. Compare the result from my original code
    – d-cmst
    Commented May 14, 2014 at 23:37
  • uhm... I tried many times and my code does work in the first case.
    – d-cmst
    Commented May 14, 2014 at 23:41
  • @dcmst which version of tcolorbox do you use? Commented May 14, 2014 at 23:48
  • @dcmst please see my updated answer. Commented May 15, 2014 at 0:16
  • 1
    Just for clarification: starting from tcolorbox 3.00 (2014/05/08), the segmentation code can also be used with enhanced; I call it: freelance everywhere :-) Commented May 15, 2014 at 6:07

You must log in to answer this question.

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