Tcolorbox
包不能正确识别奇数/偶数。来自这里对于双面文档不再正确工作
\documentclass[]{article}
\RequirePackage{changepage}
\RequirePackage[breakable, many]{tcolorbox}
\usepackage{lipsum}
\newcommand\printpage{%
Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.
}
\NewTColorBox{SomeBox}{+O{}}{%
breakable, enhanced,
check odd page,
lowerbox=ignored,
underlay={%
if odd page={%
\draw[red!75!black,line width=1pt]
(frame.north east)
--(frame.south west);%
}{%
\draw[red!75!black,line width=1pt]
(frame.north west)
--(frame.south east);%
},
},%
#1
}
\begin{document}
\begin{SomeBox}
\printpage
\lipsum*
\bigskip
\printpage
\end{SomeBox}
\printpage
\end{document}
答案1
如果您if odd page
直接在框代码内(而不是在里面underlay={...}
)使用检查,它会起作用,如下所示:
\documentclass{article}
\usepackage{changepage}
\usepackage[breakable, many]{tcolorbox}
\usepackage{lipsum}
\newcommand\printpage{%
Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.\par
}
\NewTColorBox{SomeBox}{+O{}}{%
breakable, enhanced,
check odd page,
lowerbox=ignored,
if odd page={
underlay={
\draw[blue!75!black,line width=1pt]
(frame.north east)
--(frame.south west);
}
}{
underlay={
\draw[red!75!black,line width=1pt]
(frame.north west)
--(frame.south east);
}
},
#1
}
\begin{document}
\begin{SomeBox}
\printpage
\lipsum*[1-3]
\par
\printpage
\end{SomeBox}
\newpage
\begin{SomeBox}
\printpage
\lipsum*[4-6]
\par
\printpage
\end{SomeBox}
\end{document}
/tcb/if odd page
我认为在参数中不起作用的原因/tcb/underlay
是它/tcb/if odd page
是一个tcolorbox
键,而不是传递给样式的值所预期的〈图形代码〉(TikZ 代码等)/tcb/underlay
。
当使用钥匙的盒子/tcb/breakable
跨页破碎时,所有部件都会得到相同的检查结果,这似乎是在盒子启动时完成的。但通过使用计数器tcbbreakpart
,您可以根据部件编号(从 1 开始)在可破碎的盒子内交替颜色或任何您想要的东西:
\documentclass{article}
\usepackage{changepage}
\usepackage[breakable, many]{tcolorbox}
\usepackage{lipsum}
\newcommand\printpage{%
Page is \thepage. It is \checkoddpage\ifoddpage odd\else even\fi.\par
}
\NewTColorBox{SomeBox}{+O{}}{%
breakable, enhanced,
check odd page,
lowerbox=ignored,
if odd page={
underlay={
\ifodd\value{tcbbreakpart}
\draw[blue!75!black,line width=1pt]
(frame.north east) -- (frame.south west);
\else
\draw[red!75!black,line width=1pt]
(frame.north west) -- (frame.south east);
\fi
}
}{
underlay={
\ifodd\value{tcbbreakpart}
\draw[red!75!black,line width=1pt]
(frame.north west) -- (frame.south east);
\else
\draw[blue!75!black,line width=1pt]
(frame.north east) -- (frame.south west);
\fi
}
},
#1
}
\begin{document}
\begin{SomeBox}
\printpage
\lipsum
\par
\printpage
\end{SomeBox}
\begin{SomeBox}
\printpage
\lipsum
\par
\printpage
\end{SomeBox}
\end{document}