根据这里的几次讨论和我自己的目的,我根据tcolorbox
包装的特殊用途制定了我的定理等。所以我只为我的盒子取了部分规则,大约四分之一\textwidth
为水平规则,大约 10 毫米为垂直规则。为此,我在我的盒子的四个角上获得了 4 个盒子,具有“经验”尺寸,即非精确尺寸......
在另一部分中,我的盒子可以被“命名”,所以我在这个宏项目中有一个处理这个目的的选项。
在带标题的框中,东北规则的长度可以比固定长度更长。我怎样才能使框对称,即使东南规则与东北规则一样长……因此根据 \widthof{title} 之类的内容添加一些长度……更一般地说,我怎样才能将标题的宽度用作尺寸,我可以在某些操作中使用它来定义规则的长度,例如……(\widthof{} 在 tcolorbox 中被拒绝作为尺寸)?
这是我使用的程序。我用阿拉伯语(一种从右到左的语言)写数学题,使用多语种,但这与语言无关。我给这个程序的主要语言是英语:
\documentclass{book}
\usepackage[most]{tcolorbox}
\usepackage{varwidth}
\tcbuselibrary{skins,breakable}
\usepackage{polyglossia}
\setmainlanguage{english}
\newfontfamily{\englishfont}{Arial}
\newcounter{proposition}[chapter]
\renewcommand{\theproposition}{\arabic{proposition}}
\newcommand{\propositionlabel}{\textbf{Prop \theproposition}}
\newcommand{\propositionnode}{%
\node[fill=blue!5!white, draw=blue!75!black, line width=.5pt, below right, minimum height=2em,
text width=.8cm, align=center] at ([xshift=3mm,yshift=-1mm]frame.north east) {\propositionlabel}}
\newenvironment{proposition}[1][]{%
\refstepcounter{proposition}%
\begin{tcolorbox}[enhanced jigsaw,breakable,colback=white,colframe=white,arc=0mm,rightrule=0mm,leftrule=0mm,toprule=0mm,
bottomrule=0mm, top=2mm,bottom=2mm,left=2mm,right=2mm,
varwidth boxed title,
attach boxed title to top right={xshift=.5mm,yshift=- \tcboxedtitleheight+.5mm},
boxed title style={enhanced,arc=0pt,outer arc=0pt,colframe=blue!75!black,right=1mm,boxrule=.5mm},
colbacktitle=blue!5!white, coltitle=black,extrude right by=-15mm,
underlay unbroken and first={%
\propositionnode;
\draw [blue!75!black,line width=.5mm]([xshift=14.75mm,yshift=.25mm]frame.north east)--+(0,-15mm);
\draw [blue!75!black,line width=.5mm]([xshift=15mm,yshift=.25mm]frame.north east)--+(-\textwidth/4,0);
\draw [blue!75!black,line width=.5mm]([yshift=.25mm]frame.north west)--+(\textwidth/4,0);
\draw [blue!75!black,line width=.5mm]([xshift=.25mm,yshift=.25mm]frame.north west)--+(0,-15mm);
},
underlay unbroken and last={%
\draw [blue!75!black,line width=.5mm]([yshift=.25mm]frame.south west)(\textwidth/4,0)--(0,0);
\draw [blue!75!black,line width=.5mm]([xshift=.25mm,yshift=.25mm]frame.south west)--+(0,15mm);
\draw [blue!75!black,line width=.5mm]([xshift=14.75mm,yshift=.25mm]frame.south east)--+(0,15mm);
\draw [blue!75!black,line width=.5mm]([yshift=.25mm]frame.south east)(3*\textwidth/4,0)--(\textwidth,0);
},
code={\ifstrempty{#1}
{\tcbset{
before upper={\parshape 4
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \hsize}
}}
{\tcbset{
title={#1},
before upper={\vspace*{\baselineskip}\parshape 3
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \hsize}
}}
}
]}{%
\end{tcolorbox}}
\begin{document}
\pagestyle{empty}
\noindent
In this document, the text would be written in arabic, a right-to-left language
\vspace{5mm}
\begin{proposition}
A non-titled proposition
\vspace{2.2cm}
\end{proposition}
\vspace{5mm}
\begin{proposition}[A long title]
A titled proposition
\vspace{2cm}
\end{proposition}
\end{document}
使用 xelatex 编译后得到以下 pdf 文件:
答案1
当框包含一个title
节点时title
,其west
锚点可用于延伸底线,但当没有定义标题时不会创建节点,此时我们需要区分有标题和无标题的框。
由于原始代码已经在code
选项中做出了这种区分,我只是将右下角定义移到了此选项中。对于无标题的情况,代码绘制 15mm 角,但对于有标题的情况,底线会延伸到标题的左边距。
顺便说一下,我还改变了角的绘制方式,现在它们用一个\draw
带有语法的命令来定义|-
,而不是两条不同的线
\documentclass{book}
\usepackage[most]{tcolorbox}
\usepackage{varwidth}
\tcbuselibrary{skins,breakable}
\usepackage{polyglossia}
\setmainlanguage{english}
\newfontfamily{\englishfont}{Arial}
\newcounter{proposition}[chapter]
\renewcommand{\theproposition}{\arabic{proposition}}
\newcommand{\propositionlabel}{\textbf{Prop \theproposition}}
\newcommand{\propositionnode}{%
\node[fill=blue!5!white, draw=blue!75!black, line width=.5pt, below right, minimum height=2em,
text width=.8cm, align=center] at ([xshift=3mm,yshift=-1mm]frame.north east) {\propositionlabel}}
\newenvironment{proposition}[1][]{%
\refstepcounter{proposition}%
\begin{tcolorbox}[enhanced jigsaw, breakable, colback=white, colframe=white, arc=0mm, rightrule=0mm, leftrule=0mm, toprule=0mm,
bottomrule=0mm, top=2mm, bottom=2mm, left=2mm, right=2mm, varwidth boxed title,
attach boxed title to top right={xshift=.5mm,yshift=- \tcboxedtitleheight+.5mm},
boxed title style={enhanced, arc=0pt, outer arc=0pt, colframe=blue!75!black, right=1mm, boxrule=.5mm},
colbacktitle=blue!5!white, coltitle=black, extrude right by=-15mm,
underlay unbroken and first={%
\propositionnode;
\draw [blue!75!black,line width=.5mm]([shift={(15mm-.5\pgflinewidth,-15mm+.5\pgflinewidth)}]frame.north east)|-([shift={(-\textwidth/4+15mm,+.5\pgflinewidth)}]frame.north east);
\draw [blue!75!black,line width=.5mm]([shift={(.5\pgflinewidth,-15mm+.5\pgflinewidth)}]frame.north west)|-([shift={(\textwidth/4,+.5\pgflinewidth)}]frame.north west);
},
underlay unbroken and last={%
\draw [blue!75!black,line width=.5mm]([shift={(.5\pgflinewidth,15mm+.5\pgflinewidth)}]frame.south west)|-([shift={(\textwidth/4,+.5\pgflinewidth)}]frame.south west);
},
code={\ifstrempty{#1}
{\tcbset{
before upper={\parshape 4
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \hsize},
underlay unbroken and last={
\draw [blue!75!black,line width=.5mm]([shift={(15mm-.5\pgflinewidth,15mm+.5\pgflinewidth)}]frame.south east)|-([shift={(-\textwidth/4+15mm,+.5\pgflinewidth)}]frame.south east);
},
}}
{\tcbset{
title={#1},
before upper={\vspace*{\baselineskip}\parshape 3
0pt \dimexpr \hsize-14mm\relax
0pt \dimexpr \hsize-14mm\relax
0pt \hsize},
underlay unbroken and last={
\draw [blue!75!black,line width=.5mm]([shift={(15mm-.5\pgflinewidth,15mm+.5\pgflinewidth)}]frame.south east)|-(title.west|-frame.south);}
}}}
]}{%
\end{tcolorbox}}
\begin{document}
\pagestyle{empty}
\noindent
In this document, the text would be written in arabic, a right-to-left language
\vspace{5mm}
\begin{proposition}
A non-titled proposition
\vspace{2.2cm}
\end{proposition}
\vspace{5mm}
\begin{proposition}[A long title]
A titled proposition
\vspace{2cm}
\end{proposition}
\end{document}
此处留下旧评论以供记录
这不是答案,而是带有图片的评论。OP 说:
当我的框有标题时,标题框的规则(使用命令 boxrule=.5mm 放置的规则)与框的东北规则(使用选项 line width=.5mm 获得的规则)不重叠。我怎样才能使规则完全重叠?
我用 xelatex 编译了代码,结果如下:
我看到标题框(已opacityframe=0.5
添加)完全对齐并与东北规则(蓝线)重叠。那么问题出在哪里?我误解了您的问题吗?