我希望在环境启动到环境结束framebox
时,每页顶部都出现(如 1B)(即,仅限第 2 页和第 3 页,而不是第 1 页,因为练习是从第 1 页中间开始的)。请参阅以下屏幕截图:exercise
exercise
![在此处输入图片描述][1]
我的 MWE 是:
\documentclass{book}
\usepackage[driver=none]{geometry}
\usepackage{fancyhdr}
\usepackage[tikz]{mdframed}
\geometry{
paperwidth=190mm,
paperheight=256mm,
asymmetric,
left=20mm,
right=20mm,
top=22.5mm,
bottom=15mm,
headsep=10.5mm,
footskip=4mm,
marginparsep=2mm,
headheight=21pt
}
\usepackage[cam,a4,center,pdflatex]{crop}
\usepackage{lipsum}
\newcounter{exercise}
\newenvironment{exercise}[1][]{
\stepcounter{exercise}%
\mdfsetup{%
backgroundcolor=green,
linecolor=blue,%
linewidth=2pt,
frametitlerule=true,
frametitlerulewidth=2.5pt,
}\relax
\begin{mdframed}%
}{%
\end{mdframed}%
}
\begin{document}
\chapter{Chapter Titlte}
\lipsum[1]
\begin{exercise}
\lipsum[1-12]
\end{exercise}
\lipsum[6-14]
\end{document}
答案1
tcolorbox
再次使用:
\documentclass{book}
\usepackage[driver=none]{geometry}
\usepackage{ifoddpage}
\usepackage[many]{tcolorbox}
\usetikzlibrary{backgrounds}
\geometry{
paperwidth=190mm,
paperheight=256mm,
asymmetric,
left=20mm,
right=20mm,
top=22.5mm,
bottom=15mm,
headsep=10.5mm,
footskip=4mm,
marginparsep=2mm,
headheight=21pt
}
\usepackage[cam,a4,center,pdflatex]{crop}
\usepackage{lipsum}
\newtcolorbox[auto counter]{exercise}[2][]{%
colback=green,
colframe=blue,
arc=0pt,
toprule=2.5pt,
bottomrule=2.5pt,
boxsep=0pt,left=2pt,right=2pt,top=2pt,bottom=2pt,
breakable,
enhanced jigsaw,
fonttitle=\fontsize{25}{17}\selectfont\bfseries,
title=\strut Exercise~\thetcbcounter: #2,
%grow to left by=-0.2in,
%enlarge left by=0.2in,
%enlarge right by=-0.4in,
overlay middle and last={
\checkoddpage
\ifoddpage
\node[anchor=north west,align=left,text width=1.5in,font=\Large\bfseries]
at ([shift={(2ex,-0.55ex)}]frame.north east) (a) {\thetcbcounter};
\begin{scope}[on background layer]
\fill[green!30] (a.south west) to[bend left] (a.north west) -- +(2in,0) |- (a.south west);
\end{scope}
\else
\node[anchor=north east,align=right,text width=1.5in,font=\Large\bfseries]
at ([shift={(-2ex,-0.55ex)}]frame.north west) (b) {\hfill\thetcbcounter};
\fi
\begin{scope}[on background layer]
\fill[green!30] (b.north east) to[bend left] (b.south east) -- +(-2in,0) |- (b.north east);
\end{scope}
},
before=\vskip\itemsep\noindent
#1}
\begin{document}
\chapter{Chapter Titlte}
\lipsum[1]
\begin{exercise}{}
\lipsum[1-12]
\end{exercise}
\lipsum[6-14]
\end{document}