tcolorbox:使用`\tcbifoddpage`

tcolorbox:使用`\tcbifoddpage`

请考虑以下 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}

这给了我想要的结果:

在此处输入图片描述

如果我在框“任务”中评论其中一个\lipsum,则该框应该只出现在一页上,但是我收到以下错误:

! 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

强制编译结束时,会出现一个框,但框的左侧或右侧没有“标题”。我是否遗漏了框定义中的某些内容或误解了文档tcolorbox

在此处输入图片描述

答案1

在需要的皮肤家庭overlay中使用。tcolorboxesenhanced

\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}

在此处输入图片描述

相关内容