![添加 tcolorbox 标签时,计数器 tcbbreakpart 会在 2 处阻塞](https://linux22.com/image/363294/%E6%B7%BB%E5%8A%A0%20tcolorbox%20%E6%A0%87%E7%AD%BE%E6%97%B6%EF%BC%8C%E8%AE%A1%E6%95%B0%E5%99%A8%20tcbbreakpart%20%E4%BC%9A%E5%9C%A8%202%20%E5%A4%84%E9%98%BB%E5%A1%9E.png)
很长的序列tcolorbox
可以分成许多个框。“中断序列的各个部分由计数器 tcbbreakpart 编号。”(手册 4.11 第 363 页)
现在,让我们为每个页面添加一个侧边标签,可以使用tcolorbox
或使用 TiKZ 制作。
tcbbreakpart当标签由 TiKZ 制作时,效果很好。
tcbbreakpart当右侧选项卡是 tcolorbox 时,在 2 处停止。
有没有什么办法可以解除柜台的封锁tcbbreakpart
?
\documentclass[twoside]{book}
\usepackage[margin=3.5cm]{geometry}
\usepackage[all]{tcolorbox}
\usepackage{eso-pic}
\usepackage{lipsum}
% Tabs with TColorBox
\newcommand{\TcolorBoxTab}[1]{
\begin{tcolorbox}[enhanced,size=normal,center upper,fontupper={\bfseries\huge\scshape},arc=3mm,width=22cm,
colback={#1!20}, rounded corners=north, sharp corners=south, bottomrule=0mm]
\underline{tcbbreakpart} stops at 2 when the tab is a tcolorbox.\\ Here \underline{tcbbreakpart} = \arabic{tcbbreakpart}
\end{tcolorbox}
}
\newcommand{\TColorBoxRightTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (RightTab1) [above,xshift=0mm,rotate=90] at
(current page.east){\TcolorBoxTab{red}};
\end{tikzpicture}
}
% Tabs with TiKz
\tikzset{RightTabStyle/.style={align=center,
text=blue!80!black,font=\scshape\bfseries\huge,
text width=23cm, text height=1cm, text depth=1.5cm,
inner sep=0pt,thick,rectangle,rounded corners=5pt,rotate=0,
draw=blue,fill=pink!50}} %
\newcommand{\TikzRightTabs}{
\begin{tikzpicture}[overlay, remember picture]
\node (RightTab1) [
RightTabStyle,
above,xshift=0mm,rotate=90] at
(current page.east) {
\underline{tcbbreakpart} works well when the tab is made with TiKZ.\\ Here \underline{tcbbreakpart} = \arabic{tcbbreakpart}
};
\end{tikzpicture}
}
%-->>> Tabs made with TColorBox block the counter of broken boxes.<<--
\AddToShipoutPicture{
%\TikzRightTabs% tcbbreakpart works well
\TColorBoxRightTabs% blocks tcbbreakpart at #2
}
\begin{document}
% Example modified from tcolorbox-example.tex (2017-09-14) by Prof. Dr. Dr. Thomas F. Sturm
\begin{tcolorbox}[enhanced jigsaw,breakable,pad at break*=1mm,
colback=blue!5!white,colframe=blue!75!black,title={Example modified from tcolorbox-example.tex (2017-09-14) by Prof. Dr. Dr. Thomas F. Sturm},
fonttitle=\huge\bfseries,
title after break={\huge\bfseries
\underline{tcbbreakpart} is \arabic{tcbbreakpart}},
watermark color=yellow,watermark text=\Roman{tcbbreakpart}]
\lipsum[1-30]
\end{tcolorbox}
\end{document}
答案1
正如 Ignasi 所写:tcbbreakpart
计数器是“唯一的”而不是per-box
计数器实体,因此在每个侧边标签框中都会发生重置——一个可能的解决方案是存储计数器值,但这非常棘手。
我已经使用(嗯,我的;-) 包xassoccnt
来提供一个存储的计数器,每次计数器增加时都会步进,并在每个侧边标签框之后tcbbreakpart
恢复其值。tcbbreakpart
我还将 移到了tab box
的底层pagebox
,以便摆脱异步发货。
旁注:在大多数情况下,最好定义专门的框而不是\begin{tcolorbox}...\end{tcolorbox}
一直使用。
\documentclass[twoside]{book}
\usepackage[margin=3.5cm]{geometry}
\usepackage[all]{tcolorbox}
\usepackage{eso-pic}
\usepackage{lipsum}
\usepackage{xassoccnt}
\newcounter{pagebox}
\newcounter{tcbbreakpartstored}[pagebox]
\DeclareAssociatedCounters{tcbbreakpart}{tcbbreakpartstored}
% Tabs with tcolorbox
\newtcolorbox{tabbox}[2][]{%
size=normal,
center upper,
fontupper={\bfseries\huge\scshape},
arc=3mm,
width=22cm,
colback={#2!20},
rounded corners=north,
sharp corners=south,
bottomrule=0mm,
before={\setcounter{tcbbreakpart}{\value{tcbbreakpartstored}+1}}% Use the stored value
}
\newtcolorbox[use counter=pagebox]{pagebox}[1][]{%
enhanced jigsaw,
remember,
breakable,
pad at break*=1mm,
colback=blue!5!white,
colframe=blue!75!black,
title={Example modified from tcolorbox-example.tex (2017-09-14) by Prof. Dr. Dr. Thomas F. Sturm},
fonttitle=\huge\bfseries,
title after break={\huge\bfseries\underline{tcbbreakpart} is \arabic{tcbbreakpart}},
underlay broken={%
\node (RightTab1) [above,xshift=0mm,rotate=90] at
(current page.east){\TcolorBoxTab{red}};
},
watermark color=yellow,
watermark text=\Roman{tcbbreakpart},
#1,
}
\newcommand{\TcolorBoxTab}[1]{%
\begin{tabbox}{#1}
\underline{tcbbreakpart} continues when the tab is a tcolorbox.\\ Here \underline{tcbbreakpart} = \arabic{tcbbreakpart}.
\end{tabbox}
}
\newcommand{\TColorBoxRightTabs}{%
\begin{tikzpicture}[overlay, remember picture]
\node (RightTab1) [above,xshift=0mm,rotate=90] at
(current page.east){\TcolorBoxTab{red}};
\end{tikzpicture}%
}
% Tabs with TiKz
\tikzset{RightTabStyle/.style={
align=center,
text=blue!80!black,
font=\scshape\bfseries\huge,
text width=23cm,
text height=1cm,
text depth=1.5cm,
inner sep=0pt,
thick,
rectangle,
rounded corners=5pt,
rotate=0,
draw=blue,
fill=pink!50}
} %
\newcommand{\TikzRightTabs}{%
\begin{tikzpicture}[overlay, remember picture]
\node (RightTab1) [
RightTabStyle,
above,xshift=0mm,rotate=90] at
(current page.east) {
\underline{tcbbreakpart} works well when the tab is made with TiKZ.\\ Here \underline{tcbbreakpart} = \arabic{tcbbreakpart}
};
\end{tikzpicture}%
}
%-->>> Tabs made with TColorBox block the counter of broken boxes.<<--
\AddToShipoutPicture{
% \TikzRightTabs% tcbbreakpart works well
% \TColorBoxRightTabs% blocks tcbbreakpart at #2
}
\begin{document}
% Example modified from tcolorbox-example.tex (2017-09-14) by Prof. Dr. Dr. Thomas F. Sturm
\begin{pagebox}
\lipsum[1-30]
\end{pagebox}
% Another pagebox
\begin{pagebox}
\lipsum[1-30]
\end{pagebox}
\end{document}