# Fill the lower part with lines for tcolorbox

Using the tcolorbox package to produce exercises for a textbook, I use the option invisible to let space for students for writing their solutions.

For that, I want to let the blank space of the lower part, filled by horizontal lines, to let the students write comfortably. This must be done for the long exercises, taking more than one page, too, of course. How can I do this?

Note that we can obtain a grid with the option help lines, but this option induces a grid not lines... So can we put a similar option what gives only horizontal and not vertical lines ?

I give a MWE:

\documentclass{article}

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

\NewTColorBox[auto counter]{exercise}{m+O{}}{%
enhanced,
breakable,
colframe=green!20!black,
colback=yellow!10!white,
coltitle=green!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
(interior.north west) circle (2cm);
\end{tcbclipinterior}},
title={Exercise~ \thetcbcounter:},
label={exercise:#1},
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:
\vspace*{5cm}   %% more space on solution for clarity
$f^\prime(x) = \cos((\sin x)^2) 2\sin x \cos x.$
\end{exercise}

\tcbstoprecording
\end{document}


and its compilation: The lowerbox is not an special node like title, interior or frame, but it's the space below segmentation node, therefore you can use \tcbsebmentstate switch to know if the corresponding box fragment contains or not the lower part. Following code shows a possible solution using tcbsegmentstate inside etoolbox conditionals. By the way, etoolbox is already loaded by tcolorbox, you don't need to charge it explicitly.

\documentclass[a4paper]{article}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\usepackage{lipsum}

\newtcolorbox{mybox}[]{
enhanced,
breakable,
underlay unbroken and first={%
\ifnumequal{\tcbsegmentstate}{1}{
\begin{tcbclipinterior}
\draw[help lines, ystep=\baselineskip, xstep=\linewidth] (segmentation.west) grid (frame.south east);
\end{tcbclipinterior}
}{}
},
underlay middle and last={%
\ifnumequal{\tcbsegmentstate}{1}{
\begin{tcbclipinterior}
\draw[help lines, ystep=\baselineskip, xstep=\linewidth] (segmentation.west) grid (frame.south east);
\end{tcbclipinterior}
}{\ifnumequal{\tcbsegmentstate}{2}{
\begin{tcbclipinterior}
\draw[help lines, ystep=\baselineskip, xstep=\linewidth] (frame.north west) grid (frame.south east);
\end{tcbclipinterior}
}{}
}
},
#1
}

\begin{document}
\begin{mybox}
\lipsum
\tcblower
\lipsum
\end{mybox}
\end{document} • Thank you for your answer, which does exactly my purpose, for this example. The use of the \tcbsegmentstate macro is ingenuous, but I don't understand very well its use... I will read the doc about the macros underlay unbroken, underlay middle etc.. Many thanks – Faouzi Bellalouna Aug 30 '19 at 13:23
• Othe thing please. Your use of xstep and ystep is beautiful for help line but I haven't found it in the doc of the package ! curious ! – Faouzi Bellalouna Aug 30 '19 at 13:39
• These are TiKZ options and commands. You can find them into pgfmanual – Ignasi Aug 30 '19 at 13:47