我使用 tcolorbox 来生成带框定理,其中标题是一个框,我想根据框的宽度在框标题后面的某个距离处开始定理文本。为此,我使用命令set parshape
在第一行上放置缩进。我想使用宏根据框的宽度进行缩进\tcbsetmacrotowidthofnode
,这可以计算此宽度(命令\mywidth
),但我无法在 parshape 中使用它。请注意,我可以使用此框的高度来放置框架的长度,没有任何问题。
我给出了我使用的文件,其中可以注意到我使用了缩进命令{\hsize-(width("Theorem")+0.666em+10.5mm)}
,这是可以接受的,而不是我想要的命令,例如{\hsize-\mywidth}
。请注意,当是单位时可以接受此命令\tcbcounter
,但当是十分之一时则不能接受。我使用 Xelatex 进行编译。
我的问题当然是:如何使用框宽度以合适的方式缩进我的环境文本?
\documentclass{book}
\usepackage[most]{tcolorbox} %So called package for boxing and so...
\usetikzlibrary{calc} % for the let-syntax etc
\RequirePackage{tikz}
\makeatletter %% MACRO ENABLING USE OF SETCOUNTER FOR TCOLORBOX
\newcommand{\settcbcounter}[2]{%
\@ifundefined{c@tcb@cnt@#1}{%
\GenericError{Error}{counter name #1 is no tcb counter }{}{}%
}{%
\setcounter{tcb@cnt@#1}{#2}%
}
}
\makeatother
\newlength\LineW
\setlength\LineW{0.5mm}
\tikzset{
frameline/.style={
draw=red!75!black,line width=\LineW
}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Arabic Commands and fonts
\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\setmainfont[Script=Arabic]{Arial} %% can use any font
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\myboxnode}[1]{%
\node[
fill=red!5!white, draw=red!75!black, line width=.5pt,
below left, minimum height=.1em,
align=center,
font=\bfseries
] (tmpbox) at
([xshift=-1mm-0.5\LineW,yshift=-1mm-0.5\LineW]frame.north east)
{\RL{#1 {\normalsize \thetcbcounter}}}}
\newtcolorbox[auto counter,number within=chapter,
number freestyle={\noexpand\arabic{\tcbcounter}}]{theo}[1][]{%
enhanced jigsaw,
breakable,
colback=white,
opacityframe=0,
top=2mm, bottom=2mm,
left=2mm, right=2mm,
% drawing corners on top and title
underlay unbroken and first={%
\myboxnode{Theorem};
\tcbsetmacrotoheightofnode\HHH{tmpbox}
% \global\let so it's available outside the underlay unbroken and first
\global\let\myheight\HHH
\tcbsetmacrotowidthofnode\BBB{tmpbox}
\global\let\mywidth\BBB
% draw top right frame
\draw [frameline=red]
([shift={(0, -\myheight-2.5mm)}]frame.north east) |-
([shift={(-\textwidth/4,0)}]frame.north east);
% draw top left frame
\draw [frameline=red]
([shift={(0,-\myheight-2.5mm)}]frame.north west) |-
([shift={(\textwidth/4,0)}]frame.north west);
},
% if box breaks across pages, draw corners on last part
underlay unbroken and last={%
% draw bottom right frame
\draw [frameline=red]
([shift={(0, \myheight+2.5mm)}]frame.south east) |-
([shift={(-\textwidth/4,0)}]frame.south east);
% draw bottom left frame
\draw [frameline=red]
([yshift=\myheight+2.5mm]frame.south west) |-
([xshift=\textwidth/4]frame.south west);
},
set parshape/.code={%
% 0.666em is twice the inner sep
\pgfmathsetlengthmacro{\parwidth}{\hsize-(width("Theorem")+0.666em+10.5mm)}
\tcbset{
before upper={\vspace*{.5mm}\parshape 2
0pt \parwidth
0pt \hsize}
}
},
set parshape={}
#1}
\begin{document}
\begin{theo}
The\\
First\\
Theorem
\end{theo}
\settcbcounter{theo}{9}
\begin{theo}
The\\
Tenth\\
Theorem
\end{theo}
\end{document}