我是新用户(我以前在这里问过一些问题,但那是很久以前的事情了),对课堂tcolorbox
上创建的示例框有疑问scrbook
。我想问各位大神以下几个问题:
我的 MWE。
\documentclass[twoside,chapterprefix]{scrbook}
\usepackage{showframe}
\usepackage{xcolor,graphicx,kantlipsum,multicol}
\usepackage[papersize={21cm,23cm},top=1.8cm, bottom=2cm, outer=7cm, inner=2cm, heightrounded, marginparwidth=5.0cm, marginparsep=0.5cm]{geometry}
\usepackage{sidenotes}
%The package provides an environment for coloured and framed text boxes with a heading line
\usepackage[most]{tcolorbox}
\usepackage{wallpaper}
%Define framed box for example problem
\newtcolorbox[auto counter,number within=chapter]{examplebox}[2][]{breakable,fonttitle=\bfseries, title=\Large{\textbf{Problem.}}~\thetcbcounter #2,#1}
\begin{document}
\chapter{Introduction}
\begin{examplebox}[label={myautocounter},left=1pt]{}
\begin{marginfigure}[0cm]
\includegraphics[scale=0.25]{example-image}
\label{fig:dsc4336}
\caption{I am a figure}
\end{marginfigure}
I USE MY "EXAMPLEBOX" AS USUAL TEXT AND MARGIN FIGURE WORK AS THEY SHOULD BE BUT I WANT MY EXAMPLE BOX SPREAD OUT TO THE RIGHT MARGIN ON AN ODD PAGE, BREAKABLE, AND SPREAD OUT TO THE LEFT MARGIN ON THE EVEN PAGE.
\end{examplebox}
\newpage
\begin{examplebox}[label={myautocounter},left=1pt]{}
\begin{marginfigure}[0cm]
\includegraphics[scale=0.25]{example-image}
\label{fig:dsc4336}
\caption{I am a figure}
\end{marginfigure}
I USE MY "EXAMPLEBOX" AS USUAL TEXT AND MARGIN FIGURE WORK AS THEY SHOULD BE BUT I WANT MY EXAMPLE BOX SPREAD OUT TO THE RIGHT MARGIN ON AN ODD PAGE, BREAKABLE, AND SPREAD OUT TO THE LEFT MARGIN ON THE EVEN PAGE.
\end{examplebox}
\end{document}
在我的 MWE 中,当我尝试扩展它时,文本也会延伸到外边距。我需要制作一个可破坏的框,覆盖所有页面宽度(textwidth+marginparsep+marginparwidth),但仍然能够同时将文本插入文本区域并将图形插入边距区域。
非常感谢任何帮助、建议和评论。
祝你今天过得愉快。
答案1
我认为你不可能拥有你想要的一切。我几乎可以肯定,如果不认真努力,你不可能拥有你想要的一切。
这里有两种可能的方法。两者都适用tcolorbox
于文本和边缘图像内容。
这使用了一种修改后的环境形式
examplebox
。缺点是,在偶数页上必须首先指定边缘图像,而在奇数页上则必须第二个指定边缘图像,即内容切换不是自动的。这会自动切换内容。缺点是您必须使用
\tcbsidebyside[example box]{<text column content>}{<marginal image column content>}
来指定文本和边距图像。如果您想要标题,则将其作为参数传递给example box
。
我用 4 个例子来说明这一点:奇数页和偶数页上各举一个每种类型的例子。
\begin{examplebox}{}
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.
\tcblower
\includegraphics[scale=0.25]{example-image}
\captionof{figure}{I am figure}\label{fig:example-image}
\end{examplebox}
这里,边缘图像位于其后\tcblower
,文本位于其前。可以向环境传递一个可选参数,以在本地覆盖设置。强制参数包含标题(此处为空)。
\tcbsidebyside[example box=Title here]{%
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.%
}{%
\includegraphics[scale=0.25]{example-image-a}
\captionof{figure}{I am a figure}\label{fig:example-image-a}%
}
这里example box
使用了 style 和 title Title here
。文本放在第一个强制参数中;边缘图像放在第二个强制参数中。
\newpage
我们的奇怪页面就这样结束了。
\begin{examplebox}{}
\includegraphics[scale=0.25]{example-image-b}
\captionof{figure}{I am b figure}\label{fig:example-image-b}
\tcblower
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.
\end{examplebox}
这里,边缘图像位于 之前\tcblower
,而文本位于 之后。参数与前面相同。
\tcbsidebyside[example box]{% with no title
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.%
}{%
\includegraphics[scale=0.25]{example-image-c}
\captionof{figure}{I am c figure}\label{fig:example-image-c}%
}
这里,example box
样式调用时没有参数,因此在这种情况下标题为空。与之前一样,文本在第一个强制参数中指定;边距图像在第二个参数中指定。由于我们在偶数页上,因此排版时将自动切换此顺序,即边距图像将设置在框的左侧,文本将设置在右侧。
我们的偶数页到此结束。
第一种方法与examplebox
环境已被修改为使用自定义计数器,以便说明第二种方法如何集成到单个编号序列中,以防您想混合使用这两种方法。如果不想,您可以更方便地坚持使用tcbcounter
。
\documentclass[twoside,chapterprefix]{scrbook}
\usepackage{graphicx}
\usepackage[showframe, papersize={21cm,23cm},top=1.8cm, bottom=2cm, outer=7cm, inner=2cm, heightrounded, marginparwidth=5.0cm, marginparsep=0.5cm]{geometry}% I guess you know this package tramples wantonly on KOMA-script's careful typographic design?!
%The package provides an environment for coloured and framed text boxes with a heading line
\usepackage[most]{tcolorbox}
\NewTColorBox
[%
use counter=mytcbcounter,
]{examplebox}{ O{} +m }{%
breakable,
toggle enlargement=evenpage,
grow to right by=\marginparwidth+\marginparsep,
sidebyside,
lower separated=false,
if odd page={lefthand width=\textwidth-2.5mm-2pt, before lower app=\centering,}{righthand width=\textwidth-2.5mm-2pt, before upper app=\centering},
boxrule=.5mm,
boxsep=1mm,
left=1pt,
right=1pt,
sidebyside gap=\marginparsep+2mm+2pt,
fonttitle=\bfseries\Large,
title={Problem~\themytcbcounter #2},
#1,
}
\tcbset{%
example box/.style={
breakable,
toggle enlargement=evenpage,
grow to right by=\marginparwidth+\marginparsep,
sidebyside,
lower separated=false,
if odd page={lefthand width=\textwidth-2.5mm-2pt, before lower app=\centering,}{before upper app=\centering, righthand width=\textwidth-2.5mm-2pt, sidebyside switch},% p.125 of manual
boxrule=.5mm,
boxsep=1mm,
left=1pt,
right=1pt,
sidebyside gap=\marginparsep+2mm+2pt,
fonttitle=\bfseries\Large,
code=\refstepcounter{mytcbcounter},
title={Problem~\themytcbcounter{} #1},
},
}
\newcounter{mytcbcounter}
\setcounter{mytcbcounter}{0}
\numberwithin{mytcbcounter}{chapter}
\begin{document}
\chapter{Introduction}
\begin{examplebox}{}
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.
\tcblower
\includegraphics[scale=0.25]{example-image}
\captionof{figure}{I am figure}\label{fig:example-image}
\end{examplebox}
\tcbsidebyside[example box=Title here]{%
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.%
}{%
\includegraphics[scale=0.25]{example-image-a}
\captionof{figure}{I am a figure}\label{fig:example-image-a}%
}
\newpage
\begin{examplebox}{}
\includegraphics[scale=0.25]{example-image-b}
\captionof{figure}{I am b figure}\label{fig:example-image-b}
\tcblower
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.
\end{examplebox}
\tcbsidebyside[example box]{% with no title
I use my ``examplebox'' as usual text and margin figure work as they should be but I want my example box spread out to the right margin on an odd page, breakable, and spread out to the left margin on the even page.%
}{%
\includegraphics[scale=0.25]{example-image-c}
\captionof{figure}{I am c figure}\label{fig:example-image-c}%
}
\end{document}