1

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

13
  • Too many questions in one, sorry and fragments of code
    – user31729
    Commented Oct 12, 2017 at 17:18
  • Do you think that I must divide it in many questions ? Commented Oct 12, 2017 at 17:23
  • I have divided it in 4 "sub-questions". Thank you for your interest. Commented Oct 12, 2017 at 17:47
  • I don't understand the question so I don't know if this comment is even pertinent. Do you know that node anchors are on the external border while lines (\draw) are drawn with coordinates on its center? Try something like: \node[draw, line width=1mm, minimum size=1cm](a){};\draw[red, line width=1mm, opacity=.5] (a.north east)rectangle(a.south west);. May be your problem is related with this behaviour.
    – Ignasi
    Commented Oct 12, 2017 at 19:53
  • Why do you define newenvironments with its associated counter instead of a tcolorbox with an auto counter option?
    – Ignasi
    Commented Oct 12, 2017 at 19:55

1 Answer 1

4

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?

5
  • @Ignasi Very good work. I don't know where was the problem !! I think that it's related with my other environment "definition", what I putted in a first post before this update for simplification... I'll update my post, where the actual problem will be that of the south-east rule for the titled case. Thanks Commented Oct 13, 2017 at 7:33
  • @FaouziBellalouna I've updated my answer. Hope it helps.
    – Ignasi
    Commented Oct 13, 2017 at 9:36
  • @Ignasi It's exactly my purpose. Many thanks. I'll be very gratefull if you can see my other questions, related to this one : tex.stackexchange.com/questions/395878/… and this one: tex.stackexchange.com/questions/395879/… Commented Oct 13, 2017 at 9:46
  • There is a small problem yet ! For the not long titles, something like \begin{proposition}[A title]. The title ends before the end of the rule. So how to put the make the box title ending at least on the end of the rule, so at the length \textwidth/4 ? Commented Oct 13, 2017 at 10:29
  • @FaouziBellalouna Tricky solution, move the original bottom right corner to definition code and left inside the titled option two add a line from the end of the corner to the end of the title. I'll try to add this solution later.
    – Ignasi
    Commented Oct 13, 2017 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .