在 tcolorbox 中使用 parbox=false 时可以避免边距项目缩进吗?

在 tcolorbox 中使用 parbox=false 时可以避免边距项目缩进吗?

对于书籍项目,示例、定理等都使用 进行样式化tcolorbox。(这部分实际上没有可协商的 - LaTeX 代码由 PreTeXt 生成。)

我一直在尝试弄清楚如何将一些数字以及旁注放入边缘。

我最近尝试使用eso-pic,但遇到了一个问题:如果我想要放在边距中的图形是跨越 3 页的示例(即 tcolorbox 环境)的一部分,则我无法在第二页上获得图形。 (该\AddToShipoutPicture*命令从 tcolorbox 的顶部获取其页面引用。)

我发现这个例子,它在图形/旁边的边缘创建一个 tcolorbox。

这几乎完全符合我的要求。但是exampletcolorbox 使用了选项parbox=false,因为我们想要示例中的段落。使用此选项后,边距中的图形将缩进 30pt。

除了对示例内部/外部的图形使用单独的环境之外,还有其他方法可以避免这种情况吗?这里有一个例子来说明:

\documentclass[twoside]{article}
\usepackage[breakable, theorems, skins]{tcolorbox}
%\tcbset{enhanced}
\usepackage[showframe,letterpaper]{geometry}
\usepackage{ifthen}
\usepackage{lipsum}
\geometry{inner=1in,textheight=9in,textwidth=320pt,marginparwidth=150pt,marginparsep=20pt,bottom=1in,footskip=29pt}


\newtcbtheorem[number within = section]{myexample}{Example}%
    {breakable,
    colback=white, colbacktitle=white, coltitle=black,
        parbox=false,}{ex}

\newtcbtheorem[number within=section]{myfig}{My Theorem}%
    {colback=white, colbacktitle=white,coltitle=black,
     fonttitle=\bfseries,
     }{th}    

\newsavebox{\mymargbox}
\newcommand{\marginfig}[1]{%
\sbox{\mymargbox}{\vbox{%
       \linewidth=\marginparwidth%
       #1%
   }}
   \ifthenelse{\isodd{\thepage}}{
   \leftskip -325pt%
   \usebox{\mymargbox}
   \leftskip 325pt%
   }
   {\leftskip 186pt%
   \usebox{\mymargbox}
   \leftskip -186pt%
   }
  \vspace*{-\ht\mymargbox}
  }
\begin{document}
\begin{myexample}{title}{label}
{
\lipsum[1]

\par

\lipsum[2]

{

\marginfig{
\begin{myfig}{title2}{label2}
\begin{itemize}
\item An item
\item Another item
\item A somewhat longer item that is a bit longer than the margin width
\end{itemize}
\end{myfig}
}

}

\lipsum[5]
}
\end{myexample}

{

\marginfig{
\begin{myfig}{title3}{label3}
\begin{itemize}
\item An item
\item Another item
\item A somewhat longer item that is a bit longer than the margin width
\end{itemize}
\end{myfig}
}

}


\lipsum[1-2]

{

\marginfig{
\begin{myfig}{title4}{label4}
\begin{itemize}
\item An item
\item Another item
\item A somewhat longer item that is a bit longer than the margin width
\end{itemize}
\end{myfig}
}

}

\lipsum[3]

\par

\begin{myexample}{Title5}{label5}
\lipsum[2]


{

\marginfig{
\begin{myfig}{title6}{label6}
\begin{itemize}
\item An item
\item Another item
\item A somewhat longer item that is a bit longer than the margin width
\end{itemize}
\end{myfig}
}

}

\end{myexample}
\end{document}

MWE 的输出

答案1

我建议采用另一种方法(更容易理解)将定理框放在边缘。

使用该包,xcoffin您可以将任何材料放在页面的任何位置。参考点是当前插入点。

因为有些定理来自 tcolorbox 内部,而另一些定理来自文本区域,所以需要两个宏来解释所涉及的不同边距。

(1)\insertTheoBox{<content>}{<vertical shift>}

(2)\insertTheoPara{<content>}{<vertical shift>}

垂直移位允许边距区域内的垂直位移。

宏中使用了两个内部“盒子”:\Framex一个是零深度盒子,允许\Theox盒子在适当的位置连接。

然后将组装的结果排版到边缘区域。

X

更新修正了一些小问题。没有固定尺寸。

%%%% version 3

\documentclass[twoside]{article}
\usepackage[breakable, theorems, skins]{tcolorbox}
%\tcbset{enhanced}
\usepackage[showframe,letterpaper]{geometry}
\usepackage{ifthen}
\usepackage{lipsum}
\geometry{inner=1in,textheight=9in,textwidth=320pt,marginparwidth=150pt,marginparsep=20pt,bottom=1in,footskip=29pt}

\newtcbtheorem[number within = section]{myexample}{Example}%
{breakable,
    colback=white,
    colbacktitle=white,
    coltitle=black,
    parbox=false,
 %  boxsep=14mm,  % for testing
}{ex}

\newtcbtheorem[number within=section]{myfig}{My Theorem}%
{colback=white, colbacktitle=white,coltitle=black,
    fonttitle=\bfseries,
}{th}  


%%*************************************************************** v3
\usepackage{xcoffins} %added
\NewCoffin\Framex
\NewCoffin\Theox

\usepackage{changepage} %added
\strictpagecheck

\newlength{\Textw} % save textwidth outside the boxes
\setlength{\Textw}{\textwidth}
\newlength{\Hshift}
\newlength{\Mshift}

\newcommand*{\calculateMshift}{%
    \checkoddpage
    \ifoddpage
        \setlength{\Mshift}{\marginparsep}
    \else
        \setlength{\Mshift}{\dimexpr-\marginparsep-\textwidth-\marginparwidth\relax}
    \fi}

    \newcommand*{\calculateHshift}{%
    \checkoddpage
    \ifoddpage
        \setlength{\Hshift}{\dimexpr\Textw/2-\tcbtextwidth/2\relax}
    \else
        \setlength{\Hshift}{\dimexpr-\Textw/2+\tcbtextwidth/2\relax}
    \fi}
    
\newcommand{\insertTheoBox}[2]{% v2 updated         
    \par %start a new line
    \calculateMshift
    \calculateHshift    
    \SetHorizontalCoffin\Framex{\color{blue}\rule{\tcbtextwidth}{0pt}} %clear box Framex
    \SetVerticalCoffin\Theox{\marginparwidth}{#1}% fill box \Theox
    \JoinCoffins*\Framex[r,vc]\Theox[l,vc](\dimexpr\Mshift+\Hshift\relax,#2)%join boxes
    \noindent\TypesetCoffin\Framex\\[-2\baselineskip] %typeset assembly
}

\newcommand{\insertTheoPara}[2]{% v2 updated
    \par
    \calculateMshift    
    \SetHorizontalCoffin\Framex{\color{red}\rule{\textwidth}{0pt}}
    \SetVerticalCoffin\Theox{\marginparwidth}{#1}
    \JoinCoffins*\Framex[r,vc]\Theox[l,vc](\Mshift,#2)  
    \noindent\TypesetCoffin\Framex\\[-2\baselineskip]
}
%%***************************************************************

\begin{document}    

    \begin{myexample}{title}{label}
        1. \lipsum[1]           
        \insertTheoBox{%
            \begin{myfig}{title1}{label1}
                \begin{itemize}
                    \item An item
                    \item Another item
                    \item A somewhat longer item that is a bit longer than the margin width
                \end{itemize}
            \end{myfig}
        }{70pt}         
                
    2.  \lipsum[2]          
    \insertTheoBox{%
        \begin{myfig}{title2}{label2}
            \begin{itemize}
                \item An item
                \item Another item
                \item A somewhat longer item that is a bit longer than the margin width
            \end{itemize}
        \end{myfig}
    }{50pt}
            
    3.  \lipsum[5]      
    \end{myexample}

    \insertTheoPara{%       
    \begin{myfig}{title3}{label3}
        \begin{itemize}
            \item An item
            \item Another item
            \item A somewhat longer item that is a bit longer than the margin width
        \end{itemize}
    \end{myfig}
        }{-40pt}    

    
    4.  \lipsum[1-2]                    
    \insertTheoPara{%
    \begin{myfig}{title4}{label4}
        \begin{itemize}
            \item An item
            \item Another item
            \item A somewhat longer item that is a bit longer than the margin width
        \end{itemize}
    \end{myfig}
    }{-20pt}
    
    5.  \lipsum[3]  
    
        \insertTheoPara{%
        \begin{myfig}{title5}{label7}
            \begin{itemize}
                \item An item
                \item Another item
                \item A somewhat longer item that is a bit longer than the margin width
            \end{itemize}
        \end{myfig}
    }{-250pt}
    
    \begin{myexample}{Title5}{label5}
    6.  \lipsum[2]  
    
        \insertTheoBox{%
        \begin{myfig}{title6}{label6}
            \begin{itemize}
                \item An item
                \item Another item
                \item A somewhat longer item that is a bit longer than the margin width
            \end{itemize}
        \end{myfig}
    }{60pt}     
            
    \end{myexample}
\end{document}

边距框及其位置将根据页面几何形状或文本区域中框的内部几何形状的变化而自动调整。

对于下图

\geometry{inner=1in,textheight=9in,
    textwidth=220pt, % changed <<<<<
    marginparwidth=220pt,  % changed <<<<<
    marginparsep=40pt,  % changed <<<<<
    bottom=1in,footskip=29pt}

    \newtcbtheorem[number within = section]{myexample}{Example}%
{breakable,
    colback=white,
    colbacktitle=white,
    coltitle=black,
    parbox=false,
    boxsep=14mm,  % added <<<<<
}{ex}

是

相关内容