2

Using the tcolorbox package to produce exercises for a textbook, I use the option invisible to let space for students for writing their solutions. In practice, the students need more space to write the solution than take the solution written. So how can I add a vertical space, say 20mm, for the option invisible? More, how can I play on this space, so add 10mm in the invisible part for short exercises, and 20mm for long ones ?

I give the program used:

\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*}
\tcblower
The derivative is:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\tcbstoprecording
\end{document}
  • Please edit your post to add the invisible option where you used to place it. (And may be comment it out) – koleygr Sep 27 '18 at 8:06
  • @koleygr This option is made with the command lowerbox=invisible, – Faouzi Bellalouna Sep 27 '18 at 8:40
2

Not sure about this answer, but you can always fix a certain height for the whole box or add to natural height some space. This space is divided between top and lower parts but you decide how. If all should go to lower part, use space to lower option. More information in section 4.10 Height control.

\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*}
\tcblower
The derivative is:
\[f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.\]
\end{exercise}

\begin{exercise}{Ex2}[coltitle=cyan!80!black, add to natural height=2cm, space to lower]
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}

enter image description here

| improve this answer | |
  • Sorry to comment your solution one year after. This solution will be very useful for me if I can "automate" the command add to natural height=2cm, so to transform it to add to natural height=xx cm, where xx is a variable, I can choose. Any Idea ? – Faouzi Bellalouna Aug 29 '19 at 10:22
  • It was very simple to "automate" it ... It suffices to add a variable, as {m+O{}+m}, then to add a command add to natural height=#3cm, space to lower, so then choose a value for #3 instead of 2 to obtain #3 cm. Have you a more beautiful idea ? Thank you – Faouzi Bellalouna Aug 29 '19 at 13:46
  • This is the idea I was going to propose. Good job. – Ignasi Aug 29 '19 at 17:04
  • @FaouziBellalouna Just a comment from tcolorbox documentation about add to natural height (page 53): "The height control keys are only applicable to unbreakable boxes. If a box is set to be /tcb/breakable, the height is always computed according to the natural height." So it seems that you can not modify lower part height in breakable boxes without undesired effects. – Ignasi Aug 30 '19 at 8:36
  • Yes I saw this on my breakable boxes, so any other idea is welcome. Many thanks – Faouzi Bellalouna Aug 30 '19 at 13:26

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.