# How can i customise the breakable box

In my example below, I have a problem with my breakable box, he does not want to ride.

\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[utf8]{inputenc}
\usepackage[frenchb]{babel}
\usepackage[most]{tcolorbox}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage[left=4cm,right=3cm,top=3cm,bottom=3cm]{geometry}

\usepackage{etoolbox}
\definecolor{tcbcolback}{RGB}{255,128,0}

\usepackage{varwidth}
\newtcolorbox{mybox}[2][]{enhanced,
before skip=0mm,after skip=0mm,
colback=black!5,colframe=black!50,boxrule=0.2mm,
height fixed for=first and middle,
attach boxed title to top left={xshift=1cm,yshift*=1mm-\tcboxedtitleheight},
boxed title style={frame code={
\path[fill=tcbcolback!60!black]
([yshift=-1mm,xshift=-1mm]frame.north west)
([yshift=-1mm,xshift=1mm]frame.north east)
\path[left color=tcbcolback!90!black,right color=tcbcolback!90!black,
middle color=tcbcolback!99!black]
([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east)
[rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east)
-- (frame.south east) -- (frame.south west)
-- ([xshift=-1mm,yshift=-1mm]frame.north west)
[sharp corners]-- cycle;
},interior engine=empty,
},
fonttitle=\bfseries,
title={#2},#1}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
enhanced jigsaw,enforce breakable,pad at break=0mm,break at=-20pt,
colframe=green!20!black,
colback=yellow!10!white,
coltitle=green!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
(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},
after upper={\par\hfill\textcolor{green!40!black}%
{\itshape Solution on page~\pageref{solution:#1}}},
lowerbox=ignored,
savelowerto=solutions/exercise-\thetcbcounter.tex,
record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
#2
}

\NewTotalTColorBox{\solution}{mm}{%
enhanced,
colframe=red!20!black,
colback=yellow!10!white,
coltitle=red!40!black,
fonttitle=\bfseries,
underlay={\begin{tcbclipinterior}
(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={Solution of Exercise~\ref{exercise:#1} on page~\pageref{exercise:#1}:},
phantomlabel={solution:#1},
attach title to upper=\par,
}{\input{#2}}

\tcbset{no solution/.style={no recording,after upper=}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\begin{mybox}[]{Exercises }
\begin{exercise}{Ex1}[coltitle=cyan!80!black]
\lipsum[1-2]
\end{exercise}
\begin{exercise}{Ex2}[coltitle=cyan!80!black]
\lipsum[1-6]
\end{exercise}
\end{mybox}
\end{document}

• You are trying to define breakable boxes inside other breakable boxes, and as CarLaTeX explained in your previous question this is not a good idea. – Ignasi Jun 3 at 15:45
• when I use unbreakable box inside breakable box it does not work. I do not know what to do. – moumou Jun 3 at 16:23
• it works. But when second box is too long for the remaining space, it jumps to second page and leaves an empty background box on first page. – Ignasi Jun 3 at 16:51
• Exactly, what is the solution then. My be changing outer box by tikz box. – moumou Jun 3 at 17:25
• As I also suggested here, you could try with the solution provided in [various defined breakable boxes inside breakable box using overlapping ](tex.stackexchange.com/questions/426981/…). This answer proposes to declare three different environments for inner boxes (exercises and solutions in your case). These environments already draw a false external box. This way you only have to fight with one level of breakable boxes. – Ignasi Jun 3 at 17:43