4

I would like to use an environment for the lower part of a tcolorbox instead of just tcblower command. I've tried with following code but it fails.

\documentclass{article}
\usepackage{tcolorbox}

\newenvironment{lowerpart}{\tcblower}{}

\begin{document}

% This works
\begin{tcolorbox}
Upper part
\tcblower
Lower part
\end{tcolorbox}

% This fails
\begin{tcolorbox}
Upper part
\begin{lowerpart}
Lower part
\end{lowerpart}
\end{tcolorbox}

\end{document}

The error shown is

! Extra }, or forgotten \endgroup.
\endminipage ...pagefalse \color@endgroup \egroup 
                                                  \expandafter \@iiiparbox \...
l.16 \begin{lowerpart}

This problem is probably realted with savelowerto option from tcolorbox fails inside a wrapper command. But as the question is not the same I don't know if same solution applies here neither how to apply to my code.

1
  • The problem is different; your \begin{lowerpart} starts a group and then \tcblower issues \end{tcb@savebox} at a different group level than expected.
    – egreg
    Sep 23, 2015 at 10:47

1 Answer 1

3

As egreg already commented, the core of the problem is the group level. \tcblower closes a group/environment (simplyfied: the minipage for the upper part) and opens another one (simplyfied: the minipage for the lower part).

Thanks to the etoolbox package which is automatically loaded by tcolorbox, you can put \tcblower at a very early point before the environment lowerpart really starts:

\documentclass{article}
\usepackage{tcolorbox}

\newenvironment{lowerpart}{}{}
\BeforeBeginEnvironment{lowerpart}{\tcblower}

\begin{document}

% This works
\begin{tcolorbox}
Upper part
\tcblower
Lower part
\end{tcolorbox}

% This works too
\begin{tcolorbox}
Upper part
\begin{lowerpart}
Lower part
\end{lowerpart}
\end{tcolorbox}

\end{document}

enter image description here

But, I would'nt lay may hand into the fire that this new environment lowerpart works in combination with trickier things like savelowerto etc.

Instead of using a real lower part, maybe, just drawing a line with \tcbline could be an alternative. This can be used without tricks:

\documentclass{article}
\usepackage[skins]{tcolorbox}

\newenvironment{lowerpart}{\tcbline}{}

\begin{document}

% This works
\begin{tcolorbox}
Upper part
\tcblower
Lower part
\end{tcolorbox}

% This works too
\begin{tcolorbox}
Upper part
\begin{lowerpart}
Lower part
\end{lowerpart}
\end{tcolorbox}

\end{document}
1
  • Thanks! First solution is good enough. With it is easier to use an environment which hides the use of tcolorbox.
    – Ignasi
    Sep 24, 2015 at 7:46

You must log in to answer this question.

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