0

Following the example in the tcolorbox manual, p. 148, I produced the following MWE:

\documentclass[11pt]{book}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[no-math]{fontspec}
% Define box for questions
\newtcbtheorem{exemplo}{\, Exemplo}%
{ % frame stuff
    breakable,
    arc=40mm,
    size=normal,
    enhanced,
    colframe=blue,
    colback=white,colbacklower=white,
    borderline={0pt}{0pt}{blue!10},
    % margens da frame
    top=0.3cm,left=0.2cm,bottom=0.2cm,right=0.2cm,
    lefttitle=0.2cm, toptitle=0.1cm,bottomtitle=0.05cm,
    coltitle=blue,
    fonttitle=\bfseries,
    colbacktitle=blue!10,
}{ex}

\newfontfamily\cooljazz[NFSSFamily=cooljazz,BoldFont={Boogaloo Regular},Scale=0.85,Ligatures=TeX]{cooljazz}
\usepackage[subdued, defaultmathsizes]{mathastext}
\MTfamily{cooljazz}
\Mathastext[cooljazz]
% Environment for solving the questions
\newenvironment{resol}
{   \MTversion{cooljazz}\MTdonotfixfonts
    \setmainfont{cooljazz}[Scale = .8, Extension = .ttf ]
}{\par} 
% define grid backround
\newtcolorbox{notebook}{
    enhanced,
    breakable,
    sharp corners,
    colback=white,
    colframe=white,
    boxrule=0mm,top=0mm,bottom=0mm,left=0mm,right=0mm,
    %left=1.3in,
    underlay={%
    breakable,
        \begin{tcbclipinterior}
            \draw[help lines,step=5mm,blue!25,shift={(interior.north west)}]
            (interior.south west) grid (interior.north east);
    \end{tcbclipinterior}}
}
\begin{document}
    Minimum Working Example
\begin{exemplo}{Exemplo}{}
\lipsum[1-1]
\linebreak
\begin{notebook}

\begin{resol}   
    \lipsum[2-5]
\end{resol} 
\end{notebook}
\end{exemplo}
\end{document} 

The result is:

enter image description here

I can't align the box at the top of the page with the book class. I can with the article class, but, either way the grid box does not break across pages... Also, the last right vertical line of the grid does not show up, neither does the last horizontal bottom line... I wonder if someone has a suggestion on how to solve this....

The problem seems to be that tcolorbox does not allow for a box inside another box to break....

Thanks in advance.

Addition:

I was able to get this effect:

enter image description here

Not perfect, but will do for now. The solution was to add

    \begin{tcbclipinterior}
        \draw[help lines, step=5mm, gray25!20, shift={(interior.north west)}]
        (interior.south west) grid (interior.north east);
    \end{tcbclipinterior}}

to the exemplobox, and then define a blank box for the heading as:

\newtcolorbox{note}{
    enhanced,
    breakable,
    sharp corners,
    colback=white,
    colframe=white,
    boxrule=-2.25mm,top=2mm,bottom=1mm,left=2mm,right=2mm}

It's still not perfect as the top of the grid shows up partially after the box title....

7
  • You are including resol box inside exemplo which has some non zero inner margins. I'm not sure if this is the real problem but you can consider it.
    – Ignasi
    Mar 21 at 10:17
  • Sorry, can't see the problem... resol is not a box, just an environment. But thanks anyway.
    – JPMD
    Mar 21 at 11:30
  • 1
    I don't know, what exactely you are trying to achieve here. If you just want to write some stuff on a fancy grid then you might want to check out the WriteOnGrid package
    – DG'
    Mar 21 at 13:15
  • @JPMD my fault. I wanted to say notebook inside exemplo
    – Ignasi
    Mar 21 at 13:46
  • 1
    @JPMD I think I've understood the problem and have written an answer with a possible solution.
    – Ignasi
    Mar 21 at 18:20

1 Answer 1

2

I understant that OP wants a breakable box whith a grid background for the lower part of the box. This can be achieved with an overlay applied only to the lower box. Something like:

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

\newtcolorbox{exemplo}[2][]{%
    enhanced, breakable, segmentation hidden, colback=white,
    colframe=blue,
   overlay={\begin{tcbclipinterior}
        \draw[help lines, step=5mm, blue!50]
        (interior.south west) grid (segmentation.south east);
    \end{tcbclipinterior}},
    title=#2,#1}

\begin{document}

\begin{exemplo}{First}
\lipsum[1]
\tcblower
\lipsum[1-5]
\end{exemplo}

\end{document}

enter image description here

The problem with original codes was the use of two nested boxes. tcolorbox cannot break them. The code in page 148, uses two boxes, one for exercices and one for solutions, but they are not nested, the remain independent.

4
  • That is it!... a million thanks as I was not aware of the overaly function...
    – JPMD
    Mar 21 at 19:38
  • I see that the grid at the top does not start on a horizontal line. The last left vertical line does not also gets overlapped with the left frame line. Is it possible to align these elements. And also have the text starting at the first line of the horizontal grid? Thanks!
    – JPMD
    Mar 22 at 17:45
  • 1
    @JPMD I've no idea, but you can always play with the grid step or some shift on the upper reference point.
    – Ignasi
    Mar 22 at 18:06
  • Adding \documentclass[11pt]{book} creates a white box in the second page!!??... the problem is due to the [11pt] argument....
    – JPMD
    Mar 22 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .