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.

  • See my comments to Gonzalo Medinas answer. – Thomas F. Sturm May 15 '14 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. – Thomas F. Sturm May 15 '14 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. – Nico Boni May 15 '14 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). – Thomas F. Sturm May 15 '14 at 7:34
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

  • 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 – Nico Boni May 14 '14 at 23:37
  • uhm... I tried many times and my code does work in the first case. – Nico Boni May 14 '14 at 23:41
  • @dcmst which version of tcolorbox do you use? – Gonzalo Medina May 14 '14 at 23:48
  • @dcmst please see my updated answer. – Gonzalo Medina May 15 '14 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 :-) – Thomas F. Sturm May 15 '14 at 6:07

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.