tcolorbox-2 中的精确尺寸

tcolorbox-2 中的精确尺寸

根据此问题发布:tcolorbox 中的精确尺寸,我还有一个问题:

如果您查看原始帖子中使用的 .tex 文件(我在此处提供)及其汇编(附件),则可以看到,当框内的文本较小时,我们可以获得一些不合适的视图,我在“Prop 3”中给出了一个例子。我如何才能自动获得合适的情况,如我在示例中给出的“Prop 4”之类的内容?

这是 .tex 文件

\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}

\vspace{10mm}

\begin{proposition}
A non-suitable small proposition
\end{proposition}

\vspace{10mm}

\begin{proposition}
\vspace{1mm}
A suitable small proposition
\vspace{5mm}
\end{proposition}
\end{document}

并使用 xelatex 进行编译:

在此处输入图片描述

答案1

tcolorbox盒子曾经有它们的natural height,但是存在几个选项可以改变这种行为。

我们需要类似 TikZ 的minimum height节点参数。height from = <min> to <max>工作原理与此类似,但该min值也适用于框中的所有片段breakable。所以我认为最好手动将height选项(它将独立于其内容固定框高度)应用于太短的框。

由于环境的实际定义proposition不允许应用可选参数,我使用\newtcolorbox命令重新定义了它。这样我们也可以使用auto counter选项(我们不需要声明额外的计数器)。问题是,title曾经是可选参数的现在变成了必需的。

\documentclass{book}

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

\usepackage{polyglossia}
\setmainlanguage{english}
\newfontfamily{\englishfont}{Arial}

\newtcolorbox[auto counter]{proposition}[2][]{%
    enhanced jigsaw, breakable, 
    colback=white, colframe=white, 
    sharp corners, 
    boxrule = 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,
        sharp corners, 
        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{#2}
        {\tcbset{
            before upper={\parshape 4
                0pt \dimexpr \hsize-14mm\relax
                0pt \dimexpr \hsize-14mm\relax
                0pt \dimexpr \hsize-14mm\relax
                0pt \hsize}}}
        {\tcbset{
            title={#2},
            before upper={\vspace*{\baselineskip}\parshape 3
                0pt \dimexpr \hsize-14mm\relax
                0pt \dimexpr \hsize-14mm\relax
                0pt \hsize}}}
    },
    #1}

\newcommand{\propositionnode}{%
\node[fill=blue!5!white, draw=blue!75!black, line width=.5pt, 
    below right, minimum height=2em, 
   text width=.8cm, align=center,
   font=\bfseries] at ([xshift=3mm,yshift=-1mm]frame.north east) {Prop \thetcbcounter}}

\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}

\vspace{10mm}

\begin{proposition}[height=1.5cm]{} %less than 1.5cm has no sense
A non-suitable small proposition
\end{proposition}

\vspace{10mm}

\begin{proposition}{}
\vspace{1mm}
A suitable small proposition
\vspace{5mm}
A suitable small proposition
\end{proposition}
\end{document}

在此处输入图片描述

相关内容