我使用了 Medina 先生提供的非常有用的代码(如下),但当示例从一页运行到另一页时,第一页底部有一行,第二页顶部有一行。有人能帮我改正吗?谢谢。
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{changepage}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{lipsum}
\definecolor{framerule}{RGB}{183,41,41}
\colorlet{tryit}{green!70!black}
\newcommand\RedBox{\textcolor{framerule}{$\square$}}
\newtcolorbox{eoexample}{
enhanced,
breakable,
check odd page,
toggle left and right,
boxrule=0pt,
colback=white,
arc=0pt,
outer arc=0pt,
top=\topsep,
bottom=\topsep,
left=0pt,
right=0pt,
boxsep=0pt,
overlay={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\node[inner sep=0pt]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\node[inner sep=0pt]
(box)
at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
{\RedBox};
\draw[framerule]
(frame.south east) --
([xshift=3pt]box.east);
\fi
}
}
\newtheoremstyle{myexa}% name
{\topsep}%Space above
{\topsep}%Space below
{}%Body font
{}%Indent amount 1
{\bfseries}% Theorem head font
{.}%Punctuation after theorem head
{.5em}%Space after theorem head 2
{}%Theorem head spec
\theoremstyle{myexa}
\newtheorem{exa}{Example}
\newenvironment{example}[1][]
{\begin{eoexample}\begin{exa}}
{\end{exa}\end{eoexample}}
\begin{document}
\begin{example}
\lipsum[1-6]
\end{example}
\clearpage
\begin{example}
\lipsum[1]
\end{example}
\end{document}
答案1
overlay
代码不仅应用于非破损框,还应用于破损框的每个片段。您可以overlay
使用选项overlay unbroken
、overlay first
、overlay last
、 ... 来决定将代码应用于哪个片段(请参阅 4.11 覆盖部分彩色盒子请参阅文档。
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{changepage}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{lipsum}
\definecolor{framerule}{RGB}{183,41,41}
\colorlet{tryit}{green!70!black}
\newcommand\RedBox{\textcolor{framerule}{$\square$}}
\newtcolorbox{eoexample}{
enhanced,
breakable,
check odd page,
toggle left and right,
boxrule=0pt,
colback=white,
arc=0pt,
outer arc=0pt,
top=\topsep,
bottom=\topsep,
left=0pt,
right=0pt,
boxsep=0pt,
overlay unbroken ={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\node[inner sep=0pt, anchor=east]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\node[inner sep=0pt, anchor=east, outer sep=0pt]
(box)
at (frame.south east)
{\RedBox};
\draw[framerule]
([xshift=-\marginparsep-\marginparwidth]frame.south west) --
([xshift=-3pt]box.west);
\fi
},
overlay first={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\fi
},
overlay last={%
\ifoddpage
\node[inner sep=0pt]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[inner sep=0pt, anchor=east, outer sep=0pt]
(box)
at (frame.south east)
{\RedBox};
\draw[framerule]
([xshift=-\marginparsep-\marginparwidth]frame.south west) --
([xshift=-3pt]box.west);
\fi
}
}
\newtheoremstyle{myexa}% name
{\topsep}%Space above
{\topsep}%Space below
{}%Body font
{}%Indent amount 1
{\bfseries}% Theorem head font
{.}%Punctuation after theorem head
{.5em}%Space after theorem head 2
{}%Theorem head spec
\theoremstyle{myexa}
\newtheorem{exa}{Example}
\newenvironment{example}[1][]
{\begin{eoexample}\begin{exa}}
{\end{exa}\end{eoexample}}
\begin{document}
\begin{example}
\lipsum[1-6]
\end{example}
\clearpage
\begin{example}
\lipsum[1]
\end{example}
\clearpage
\begin{example}
\lipsum[1]
\end{example}
\end{document}
答案2
您必须将overlay
代码用作overlay unbroken
。此外,当tcolorbox
损坏时,还要添加此代码:
overlay first={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\fi
},
overlay last={%
\ifoddpage
\node[inner sep=0pt]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[inner sep=0pt]
(box)
at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
{\RedBox};
\draw[framerule]
(frame.south east) --
([xshift=3pt]box.east);
\fi
}
平均能量损失
\documentclass{book}
\usepackage[many]{tcolorbox}
\usepackage{changepage}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{lipsum}
\definecolor{framerule}{RGB}{183,41,41}
\colorlet{tryit}{green!70!black}
\newcommand\RedBox{\textcolor{framerule}{$\square$}}
\newtcolorbox{eoexample}{
enhanced,
breakable,
check odd page,
toggle left and right,
boxrule=0pt,
colback=white,
arc=0pt,
outer arc=0pt,
top=\topsep,
bottom=\topsep,
left=0pt,
right=0pt,
boxsep=0pt,
overlay unbroken={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\node[inner sep=0pt]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\node[inner sep=0pt]
(box)
at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
{\RedBox};
\draw[framerule]
(frame.south east) --
([xshift=3pt]box.east);
\fi
},
overlay first={%
\ifoddpage
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=\marginparsep+0.5\marginparwidth]frame.north east)
{You Try It!};
\draw[framerule]
(frame.north west) -- ([xshift=-3pt]tryit.west);
\draw[framerule]
([xshift=3pt]tryit.east) --
([xshift=\marginparsep+\marginparwidth]frame.north east);
\else
\node[draw,tryit,fill=white]
(tryit)
at ([xshift=-\marginparsep-0.5\marginparwidth]frame.north west)
{You Try It!};
\draw[framerule]
(frame.north east) -- ([xshift=3pt]tryit.east);
\draw[framerule]
([xshift=-3pt]tryit.west) --
([xshift=-\marginparsep-\marginparwidth]frame.north west);
\fi
},
overlay last={%
\ifoddpage
\node[inner sep=0pt]
(box)
at ([xshift=\marginparsep+\marginparwidth]frame.south east)
{\RedBox};
\draw[framerule]
(frame.south west) --
([xshift=-3pt]box.west);
\else
\node[inner sep=0pt]
(box)
at ([xshift=-\marginparsep-\marginparwidth]frame.south west)
{\RedBox};
\draw[framerule]
(frame.south east) --
([xshift=3pt]box.east);
\fi
}
}
\newtheoremstyle{myexa}% name
{\topsep}%Space above
{\topsep}%Space below
{}%Body font
{}%Indent amount 1
{\bfseries}% Theorem head font
{.}%Punctuation after theorem head
{.5em}%Space after theorem head 2
{}%Theorem head spec
\theoremstyle{myexa}
\newtheorem{exa}{Example}
\newenvironment{example}[1][]
{\begin{eoexample}\begin{exa}}
{\end{exa}\end{eoexample}}
\begin{document}
\begin{example}
\lipsum[1]
\end{example}
\bigskip
\begin{example}
\lipsum[1-6]
\end{example}
\end{document}
输出: