使用 tcolorbox 定制可破坏的盒子

使用 tcolorbox 定制可破坏的盒子

我使用 tcolorbox 包在 polyglossia 包下在阿拉伯语环境(一种从右到左的语言)中生成彩色框。
我在附件文件中解释了环境示例中的一些命令:这里使用命令“before upper”和“after upper”来包含 tcolorbox 环境中的命令。(我给出了 example_small 环境,用于单行和双行示例,以供任何评论!)在之前,我把命令

\parshape 4
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize

这会将示例的文本向前推 7 毫米,这是示例的前三行(否则节点会叠加在文本上)。您可以在下面看到 tex 文件及其编译。现在,我有几个问题:

1/ 我对长且无标题的示例感到满意,但对于有标题的示例,tcolorbox 在推送的三行中不包括标题行(参见示例 4)。因此,在这种情况下我只想推送两行。我该怎么做?

2/ 对于损坏的示例“Ex.5”,我遇到了第二个问题,其中可以看到在中断处,环境会(自动!)复制标题的节点。这对我来说可能是一个不错的选择,现在我想研究两个选项:a/ 第一个是让环境在中断处复制其节点,然后,我如何在中断处对命令进行排序

    \parshape 4
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize

以行为作为环境的开始?

b/ 第二个选项是禁止此重复。什么选项可以使此示例节点的行为与往常一样,即可中断但不在中断处重复标题?

我给了我的 tex 文件......

    \documentclass{book}

    \usepackage[most]{tcolorbox}
    \tcbuselibrary{skins,breakable}

    \usepackage{polyglossia}
    \setmainlanguage[numerals=maghrib]{arabic}
    \setotherlanguage{english}
    \usepackage{fontspec}
    \setmainfont{Times New Roman}
    \setsansfont{Arial}
    \setmonofont{Courier New}
    \newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

    \usepackage{polyglossia}
    \setdefaultlanguage{arabic}

    \newcounter{example}[section]
    \renewcommand{\theexample}{\arabic{example}}
    \newcommand{\examplelabel}{%
    {\bfseries\large
    Ex.
    \LR{\theexample}
    }}

    \newenvironment{example_small}[1][]{%
    \refstepcounter{example}%
    \begin{tcolorbox}[enhanced,breakable,
    colback=white,  arc=0mm,
    width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
    top=1mm, bottom=1mm, left=0mm, right=0mm,
    colbacktitle=yellow, colframe=red, coltitle=black, title=#1,
    before upper={\vspace*{1.5mm}
    \parshape 3
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize
            },
    after upper app={\vspace*{1.5mm}},
    extrude right by=-5.5mm,
    overlay={%
    \node[text width=.09\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\examplelabel};}]}{%
    \end{tcolorbox}}

    \newenvironment{example}[1][]{%
    \refstepcounter{example}%
    \begin{tcolorbox}[enhanced,breakable,
    colback=white, colframe=red, arc=0mm,
    rightrule=0mm, leftrule=0mm,toprule=0mm,
    top=1mm, bottom=1mm, left=0mm, right=0mm,
    colbacktitle=green, coltitle=black, 
    title=#1,
    %title={\hspace*{2mm}#1},
    extrude right by=-5.5mm,
    before upper={\parshape 4
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize},
    overlay={%
    \node[fill=yellow, draw=red, line width=1.5pt, below right, minimum height=3em, text width=.8cm, align=center] at ([xshift=-.1mm]frame.north east) {\examplelabel};
    \draw [red,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
    \draw [red,line width=.5mm]([yshift=.25mm]frame.north west)--+(\linewidth,0);}
    ]}{%
    \end{tcolorbox}}


    \begin{document}
    \noindent
    \LR{
     In this document, the text would be written in arabic, a right-to-left language
    }

    \begin{example_small}
    \LR{
    A one-line example
    }
    \end{example_small}

    \begin{example_small} 
    \LR{
    A two-lines example
    }
    \\
    \LR{
    A two-lines example
    }
    \end{example_small}

    \begin{example}
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \end{example} 

    \begin{example}[\hspace*{2.5mm}\LR{Title of the example}]
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \end{example} 


    \begin{example}[\hspace*{2.5mm}\LR{A broken example}]
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    %%\vspace*{10cm}
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \end{example} 


    \end{document}

并且获得了编译

在此处输入图片描述 在此处输入图片描述

答案1

我修改了你的例子来回答问题。

对于第一个问题,before upper如果存在标题,则代码会更改,请参阅code={\ifstrempty ...

对于第二个问题, 会underlay根据中断状态而改变。我也将overlay其改为underlay,因为它几乎是相同的,但您可以对同一个框多次使用它,并且它添加的代码不会替换。

虽然不可能有\parshape断点,但可以删除重复的框:

\documentclass{book}

\usepackage[most]{tcolorbox}
\tcbuselibrary{skins,breakable}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

\usepackage{polyglossia}
\setdefaultlanguage{arabic}

\newcounter{example}[section]
\renewcommand{\theexample}{\arabic{example}}
\newcommand{\examplelabel}{%
{\bfseries\large
Ex.
\LR{\theexample}
}}

\newtcolorbox[use counter=example]{example_small}[1][]{enhanced jigsaw,breakable,
  colback=white,  arc=0mm,
  width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
  top=1mm, bottom=1mm, left=0mm, right=0mm,
  colbacktitle=yellow, colframe=red, coltitle=black, title=#1,
  before upper={\vspace*{1.5mm}
  \parshape 3
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize
        },
  after upper app={\vspace*{1.5mm}},
  extrude right by=-5.5mm,
  overlay={%
    \node[text width=.09\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\examplelabel};}
}

\newtcolorbox[use counter=example]{example}[1][]{enhanced jigsaw,breakable,
  colback=white, colframe=red, arc=0mm,
  rightrule=0mm, leftrule=0mm,toprule=0mm,
  top=1mm, bottom=1mm, left=0mm, right=0mm,
  colbacktitle=green, coltitle=black,
  title=#1,
  extrude right by=-5.5mm,
  before upper={\parshape 4
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
  code={\ifstrempty{#1}{}{%
    \tcbset{
      before upper={\parshape 3
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
    }}},
  underlay unbroken and first={%
  \node[fill=yellow, draw=red, line width=1.5pt, below right, minimum height=3em, text width=.8cm, align=center] at ([xshift=-.1mm]frame.north east) {\examplelabel};
  \draw [red,line width=.5mm]([yshift=.25mm]frame.north west)--+(\linewidth,0);
  },
  underlay unbroken and last={%
  \draw [red,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
  },
}


\begin{document}
\noindent
\LR{
In this document, the text would be written in arabic, a right-to-left language
}

\begin{example_small}
\LR{
A one-line example
}
\end{example_small}

\begin{example_small}
\LR{
A two-lines example
}
\\
\LR{
A two-lines example
}
\end{example_small}

\begin{example}
\LR{
A general example
}
\\
\LR{
A general example
}
\\
\LR{
A general example
}
\\
\LR{
A general example
}
\end{example}

\begin{example}[\hspace*{2.5mm}\LR{Title of the example}]
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\end{example}


\begin{example}[\hspace*{2.5mm}\LR{A broken example}]
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
%%\vspace*{10cm}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\end{example}


\end{document}

我还建议您使用enhanced jigsaw而不是jigsaw作为您的示例(效果是否可见取决于预览器)。

在此处输入图片描述

在此处输入图片描述

相关内容