2

I want to use the basic tool for producing exercises with tcolorbox, in a project of textbook, so I transform the option lowerbox=ignored in the option lowerbox=invisible to obtain the white space for writing solutions with students, and I remove the command after upper={...Solution on page....

More precisely, I add to \NewTColorBox[auto counter,number within=chapter]{exercise} the options

skin=bicolor,
lowerbox=invisible,
colbacklower=white,

and I remove the option

after upper={\par\hfill\textcolor{green!40!black}%
    {\itshape Solution on page~\pageref{solution:#1}}},

Now I want to have a title for my solution box, so insert a title in the beginning of the box of solution (I want a title beginning the area in white in my example). How can I do this ?

A subsidiary (and important) question: I tried to use the option skin=bicolor,lowerbox=invisible,colbacklower=white, on "real conditions", i.e. on all the exercises of a Textbook, where I use several packages, and I obtained the error message :

`! Package tikz Error: Extra options not allowed for clipping path command..
 \pgfutil@packageerror ...ge {Package #1 Error: #2}`

What's the problem here and how can I solve it?

Here is my .tex file:

\documentclass{book}

\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,breakable}

\usepackage{polyglossia}
\setmainlanguage{english}

\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    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,
%%    after upper={\par\hfill\textcolor{green!40!black}%
%%        {\itshape Solution on page~\pageref{solution:#1}}},
    skin=bicolor,
    lowerbox=invisible,
    colbacklower=white,
    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}
        \shade[inner color=red!50!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={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}
\pagestyle{empty}

\tcbstartrecording
\begin{exercise}{Ex}
An exercise.
\tcblower
A solution
\end{exercise}

\tcbstoprecording


\end{document}

and its compilation, using xelatex:

enter image description here

  • What are #1 and #2 arguments of? it might be easier to use macros like \name and \filename and define them outside the tcolorbox. – John Kormylo Nov 19 '17 at 17:05
  • #1 is the label of exercise and #2 is its text. I don't know what is the macro \name, but creating an input file with \filename, and insert it in the tcblower, after "titling" it, seems to be a good idea ! – Faouzi Bellalouna Nov 19 '17 at 17:15
  • \input reads files, so I assumed #2 was a filename. In any case, they aren't defined in this context, at least they do not contain what you think they should contain. – John Kormylo Nov 19 '17 at 17:47
  • See the command label={exercise:#1} for the use of #1 – Faouzi Bellalouna Nov 19 '17 at 17:58
  • @FaouziBellalouna: I don't understand your question. I see the title Solution of.... after using \tcbinputrecords. Also the 'subsidiary' question is not useful here -- after adding which packages you get the error? – user31729 Nov 20 '17 at 6:13
2

This adds a node below the segmentation line and shifts it inside to be aligned with the left title skip.

The \kvtcb@X macros contain the relevant lengths of separation between left upper (X=leftupper) and general box separation (X=boxsep)

\documentclass{book}

\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\tcbuselibrary{skins,breakable}

\usepackage{polyglossia}
\setmainlanguage{english}

\makeatletter
\NewTColorBox[auto counter,number within=chapter]{exercise}{m+O{}}{%
    enhanced,
    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},
    %after upper={\par\hfill\textcolor{green!40!black}%
    %    {\itshape Solution on page~\pageref{solution:#1}}},
    skin=bicolor,
    lowerbox=invisible,
    colbacklower=white,
    overlay={\node[right,inner sep=0pt,outer sep=0pt] (A) at ($(segmentation.south west)+(\kvtcb@leftupper+\kvtcb@boxsep,0)$) {Answer:};}
    savelowerto=solutions/exercise-\thetcbcounter.tex,
    record={\string\solution{#1}{solutions/exercise-\thetcbcounter.tex}},
    #2
}
\makeatother

\NewTotalTColorBox{\solution}{mm}{%
    enhanced,
    colframe=red!20!black,
    colback=yellow!10!white,
    coltitle=red!40!black,
    fonttitle=\bfseries,
    underlay={\begin{tcbclipinterior}
        \shade[inner color=red!50!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={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}
\pagestyle{empty}

\tcbstartrecording
\begin{exercise}{Ex}
An exercise.
\tcblower
A solution
\end{exercise}

\tcbstoprecording


\end{document}

enter image description here

  • Thanks. It is exactly my purpose. I don't understand what does the command \kvtcb. Can you explain it a little ? – Faouzi Bellalouna Jan 6 '18 at 17:50
  • @FaouziBellalouna: \kvtcb ... = key value of tcolorbox tcb macros, see the short explanations in the post, however, there is no explanation in the tcolorbox manual -- you will only see them if you look into tcolorbox.sty -- sometimes, this is necessary – user31729 Jan 6 '18 at 17:54
  • Good morning. I am trying to re-understand your macro.. so late because I was busy on other things ! So I have an interrogation: why the definition of the exrecise si between \makeatletterand \makeatother? Thank you – Faouzi Bellalouna Jan 18 '18 at 9:31
  • @FaouziBellalouna: Because \kvtcb@.... are @ - macros, i.e. at - letter and as such must be used inside \makeatletter...\makeatother to allow @ to be an ordinary character. We have 'thousands' of questions concerning this ;-) – user31729 Jan 18 '18 at 9:33
  • Excuse me but I have a serious problem here: with the option breakable and if the box exceed one page (I tried with \lipsum[1]\lipsum[2]\lipsum[3]\lipsum[4]\lipsum[5]) I have the error message: ! Package tikz Error: Extra options not allowed for clipping path command... How can I fix that ? – Faouzi Bellalouna Jan 18 '18 at 12:42

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.