1

Please consider the following WME:

\documentclass[12pt]{memoir}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}

    \usepackage{TikZ}
    \usetikzlibrary{calc,chains,%
                    positioning,%
                    babel
                    }
    \usepackage[many]{tcolorbox}

    \usepackage{lipsum}
%    \usepackage{showframe}
%---------------------------------------------------------------%
\newcounter{task}
%\renewcommand{\thetask}{\thechapter.\thesection-\arabic{task}}
\newtcolorbox[use counter=task,number within=section]{task}%
   {breakable,
    toggle left and right,
    boxrule=0mm,
    colback=white, colframe=red,
    top=0mm,bottom=1mm,left=1mm,right=1mm,
    arc=0mm,
    borderline={0.5pt}{0pt}{red, sharp corners},
    fontupper=\normalsize\sffamily,
    rightrule=1mm,
overlay={%
\tcbifoddpage{\node[font=\large\sffamily, text=red, inner sep=0mm,
                    below right=\marginparsep] at (frame.north east) {Task \thetcbcounter};}
             {\node[font=\large\sffamily, text=red, inner sep=0mm,
                    below left=\marginparsep]  at (frame.north west) {Task: \thetcbcounter};}
%
        }%end of overlay
    }% end of example

%---------------------------------------------------------------%
\begin{document}
    \chapter{Test}
    \label{sec:uvod}
    \section{test}
    \label{sec:uvod.test}
\lipsum[1]

\begin{task}
\lipsum[1] %<--- if I comment it, I get a error
\lipsum[2]
\end{task}    
\end{document}

This gives me desired result:

enter image description here

If I commented one of \lipsum in box "task", the box should appear only on one page, however I receive the following errors:

! Missing number, treated as zero.
<to be read again>
                   ]
l.48 \end{task}

?
! Illegal unit of measure (pt inserted).
<to be read again>
                   ]
l.48 \end{task}

?
Missing character: There is no ] in font nullfont!
Missing character: There is no a in font nullfont!
Missing character: There is no t in font nullfont!
...
[1

and on the end of forced compilation box appear, but without "title" on the left or right side of the box. Do I miss something something in my box definition or misunderstand the tcolorbox documentation?

enter image description here

  • You also need enhanced option to use overlay. – Ignasi Mar 11 '16 at 15:41
  • @Ignasi, so simple! You save my life. Can you convert your comment to an answer that I can I up-vote and accept it? or I rather erase my question, since my error is so silly ... – Zarko Mar 11 '16 at 16:20
  • It took me some time to find it! – Ignasi Mar 11 '16 at 16:31
4

Use of overlay in tcolorboxes needs enhanced skin family.

\documentclass[12pt]{memoir}
    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}

    \usepackage{TikZ}
    \usetikzlibrary{calc,chains,%
                    positioning,%
                    babel
                    }
    \usepackage[many]{tcolorbox}

    \usepackage{lipsum}
%    \usepackage{showframe}
%---------------------------------------------------------------%
\newcounter{task}
%\renewcommand{\thetask}{\thechapter.\thesection-\arabic{task}}
\newtcolorbox[use counter=task,number within=section]{task}%
   {breakable, 
    enhanced, %<----------- This line was missing
    toggle left and right,
    boxrule=0mm,
    colback=white, colframe=red,
    top=0mm,bottom=1mm,left=1mm,right=1mm,
    arc=0mm,
    borderline={0.5pt}{0pt}{red, sharp corners},
    fontupper=\normalsize\sffamily,
    rightrule=1mm,
overlay={%
\tcbifoddpage{\node[font=\large\sffamily, text=red, inner sep=0mm,
                    below right=\marginparsep] at (frame.north east) {Task \thetcbcounter};}
             {\node[font=\large\sffamily, text=red, inner sep=0mm,
                    below left=\marginparsep]  at (frame.north west) {Task: \thetcbcounter};}
%
        }%end of overlay
    }% end of example

%---------------------------------------------------------------%
\begin{document}
    \chapter{Test}
    \label{sec:uvod}
    \section{test}
    \label{sec:uvod.test}
\lipsum[1]

\begin{task}
%\lipsum[1] %<--- if I comment it, I get a error
\lipsum[2]
\end{task}    
\end{document}

enter image description here

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.