2

I would like to define an special design for the lower part of a breakable tcolorbox. And for lowerpart I mean all contents defined after \tcblower. I would like to define some overlay or borders or whatever for the lower part independently of how many pages it covers or when it starts in a broken box.

Let's suppose something like

enter image description here

A crossing line covers the lowerpart of the box. When the tcolorbox is not breakable there is no problem, because segmentation node can be used as top reference for lowerpart.

When this design is applied to a broken box I would like that this crossing line appears in all fragments which contain parts of the lowerpart. If some fragment contains part of upper part and part of lower, the line will cover only the lower part of the fragment (like in previous figure) but will cover the whole fragment if they only contain lower part.

As an example, following figure shows a "correct" left page but a incorrect "right" because the red line doesn't starts at top left corner.

enter image description here

Another example, on left page there is an unbroken box with a "correct" red line and the first fragment of a broken one with an "incorrect" red line. It shouldn't be here because this fragment doesn't contains any lowerpart text.

enter image description here

From previous examples it seems that segmentation is remembered from previous uses or definitions and is not deleted in fragments where it should not exist.

Previous examples have been obtained with variations of:

\documentclass[a5paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{geometry}
\usepackage{lipsum}

\newtcolorbox{mybox}[1][]{%
    enhanced, 
    breakable, 
    overlay unbroken={%
        \path[draw=red] (segmentation.west)--(frame.south east);},
    overlay broken={%
        \path[draw=red] (segmentation.west)--(frame.south east);},
    #1
}

\begin{document}

\begin{mybox}
This is the upper part
\tcblower
\lipsum[3]
\end{mybox}

\begin{mybox}
\lipsum[1-2]
\tcblower
\lipsum[3-4]
\end{mybox}

\end{document}

As an alternative I tried with a bicolor skin but segmentation style options is not enough flexible and segmentation code doesn't respect the frame format.

Could you suggest an alternative solution?

  • Is the concept of the lower part of a tcolorbox still maintained in breaking? Does overlay last= help instead of overlay broken=...? – user31729 Feb 22 '17 at 18:07
  • @ChristianHupfer Let me some minutes to rephrase the question, I'll try to make it more clear. – Ignasi Feb 22 '17 at 18:13
  • I think I have understood your question, but I believe you have to make something like a query whether the box is broken, has a middle or last part. I could imagine, that for the last broken part of the box, segmentation is the wrong node name, but must be replaced by frame – user31729 Feb 22 '17 at 18:23
  • @ChristianHupfer I hope the question is more clear now. The main problem is how to know which fragments contain lowerpart. – Ignasi Feb 22 '17 at 18:36
  • Yes, that's what I meant. I think the lower part (or parts of it), if broken, will be an 'ordinary' tcolorbox later on, so for this box segmentation is the wrong node, but rather frame. I agree with you that it is difficult to identify which box has (portions) of the lower or upper part – user31729 Feb 22 '17 at 18:41
4

There is an undocument macro called \tcb@segment@state which contains 0, 1, or 2. This macro is set for every unbroken box and every broken partial box with the following meaning:

  • 0: The current (partial) box contains only an upper part.
  • 1: The current (partial) box contains an upper and a lower part. The segmentation node can be used for positioning.
  • 2: The current (partial) box contains only a lower part.

The example code can be adapted as follows:

\documentclass[a5paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{geometry}
\usepackage{lipsum}

\makeatletter
\newtcolorbox{mybox}[1][]{%
    enhanced,
    breakable,
    overlay={%
      \ifcase\tcb@segment@state%
        % 0 = Box contains only an upper part
      \or%
        % 1 = Box contains an upper and a lower part
        \path[draw=red] (segmentation.west)--(frame.south east);
      \else%
        % 2 = Box contains only a lower part
        \path[draw=red] (frame.north west)--(frame.south east);
      \fi%
    }
    #1
}
\makeatother

\begin{document}

\begin{mybox}
This is the only part
\end{mybox}

\begin{mybox}
This is the upper part
\tcblower
\lipsum[3]
\end{mybox}

\begin{mybox}
\lipsum[1-2]
\tcblower
\lipsum[3-4]
\end{mybox}

\end{document}

This gives:

enter image description here

  • Thank you. May be you could consider documenting this macro. – Ignasi Mar 3 '17 at 8:33
  • @Ignasi You may be right. In this case, I would rename the macro into something 'officially' like \tcbsegmentstate to separate it from internal stuff. – Thomas F. Sturm Mar 3 '17 at 9:36

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.