1

Using the tcolorbox package to produce exercises for a textbook, I use the option invisible to let space for students for writing their solutions. Now I want to use the help lines in overlay commands only in the lower part, and not in the upper part, so get an upper part with blank background. How can I do this?

More, can I use a more general command for help lines in the lower part, which inserts only horizontal lines, and not the vertical ones?

Edit: The solution given first is not useful when the exercise breaks, where we obtain the error message: ! Package pgf Error: No shape named segmentation is known.

I give an example where I make the exercise breaked:

\documentclass{book}

\usepackage{etoolbox}
\usepackage[most]{tcolorbox}

\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    breakable,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=green!80!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
        \end{tcbclipinterior}},
    title={Exercise~ \thetcbcounter:},
    label={exercise:#1},
    attach title to upper=\quad,
    segmentation style={double=white,draw=green!20!black,double distance=1pt,solid},
    lowerbox=invisible,
    savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2
}

\begin{document}
\pagestyle{empty}
\tcbstartrecording
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
Compute the derivative of the following function:
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}
\tcblower
The derivative is:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\tcbstoprecording
\end{document}

and its compilation: enter image description here

2

Just replace (interior.south west) grid (interior.north east) by (interior.south west) grid (segmentation.east)

reedited as follows:

  1. a new command named \myunderlay is defined
  2. two tcolorbox options: underlay unbroken=\myunderlay and underlay last=\myunderlay are added in place of underlay={...}

\documentclass{book}

\usepackage{etoolbox,lipsum}
\usepackage[most]{tcolorbox}

\newcommand{\myunderlay}{
  \begin{tcbclipinterior}
        \shade[inner color=green!80!yellow,outer color=yellow!10!white]
            (interior.north west) circle (2cm);
        \draw[help lines,step=5mm,yellow!80!black,shift={(interior.north west)}]
            (interior.south west) grid (segmentation.east); % modified
          \end{tcbclipinterior}
        }

\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    breakable,
    colframe=green!20!black,
    colback=yellow!10!white,
    coltitle=green!40!black,
    fonttitle=\bfseries,
    underlay unbroken=\myunderlay,
    underlay last=\myunderlay,
    title={Exercise~ \thetcbcounter:},
    label={exercise:#1},
    attach title to upper=\quad,
    segmentation style={double=white,draw=green!20!black,double distance=1pt,solid},
    lowerbox=invisible,
    %savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2,
}

\begin{document}
\pagestyle{empty} 
\tcbstartrecording
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
Compute the derivative of the following function: 
\begin{equation*}
f(x)=\sin((\sin x)^2)
\end{equation*}

\lipsum[1-3] 
\tcblower
The derivative is:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}




\tcbstoprecording


\end{document}

enter image description hereenter image description here

  • Sorry I'm confused, but this solution is not useful when the exercise breaks, and then it gives the following error: ! Package pgf Error: No shape named segmentation is known – Faouzi Bellalouna Sep 26 '18 at 12:43
  • I think it maybe very helpful if you provide a reproducible example with the issue encountered! – Hafid Boukhoulda Sep 26 '18 at 12:51
  • Now with the edition of @PhelypeOleinik all is good. Many thanks for the two – Faouzi Bellalouna Sep 26 '18 at 14:01
  • It seems to me that there is some kind of confusion since it's @hafidBoukhoulda who reedited the answer to address the break's issue! – Hafid Boukhoulda Sep 26 '18 at 15:02

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.