[Tex/LaTex] Exact dimensions in tcolorbox

arabicpolyglossiatcolorbox

Based on several discussions here and my own purpose, I make my theorems and such, based on a special uses of the tcolorbox package. So I take only parts of the rules for my boxes, about quart of the \textwidth for the horizontal rules, and about of 10 mm for the vertical ones. I obtain with this aim 4 boxes on the 4 corners of my boxes, with "empirical", i.e. non-exact, dimensions…

In another part, my boxes can be "titled", so I have in this project of macro an option which deals with this purpose.

In the titled box case, the length of the north-east rule can be longer than the fixed length. How can I make the box symmetric, i.e. make the south-east rule as longer as the north-east one… so add some length based on something like \widthof{title}… More generally, how can I use the width of the title as a dimension, which I can use in some operations for defining the lengths of rules, for example… (\widthof{} is refused as a dimension in tcolorbox) ?

This is the program what I use. I write mathematics in arabic, a right-to-left language, using polyglossia, but it's not related with the language. I give the program with english for main language:

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

which gives after compilation with xelatex, this pdf file:

enter image description here

Best Answer

When the box contains a title a title node exists and its west anchor can be used to extend the bottom line, But when no title is defined the node is not created, then we need to distinguish between titled and untitled boxes.

As the original code, already made this distinction within code option, I've just moved the bottom right corner definition inside this option. For the untitled case the code draws the 15mm corner, but for the titled one, the bottom line is extended to reach left margin of title.

As side note, I've also changed how the corners are drawn, now they are defined with one \draw command with |- syntax instead of two different lines

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

enter image description here

Old comment left here for the records

This is not an answer but a comment with image. OP says:

When my box have a title, the rules of my title box, what I put with the command boxrule=.5mm, is not superposed with the north-east rule of the box, obtained with the option line width=.5mm. How can I make the rules exactly superposed ?

I've compiled the code with xelatex and this is the result:

enter image description here

I see that title frame (with opacityframe=0.5 added) is completely aligned and superposed with north-east rule (blue line). So where's the problem? What I misunderstand in your question?

Related Question