1

I use the tcolorbox package to produce coloured boxes in arabic environment (a right-to-left language), under the polyglossia package.
I explain some of the commands in the environment example, in the file attached: here the commands "before upper" and "after upper" are used to include commands in the tcolorbox environments. (I give the example_small environment what I use for one-lines and two-lines examples for any comments !) For before I put the commands

\parshape 4
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize

which pushes the text of the example by 7mm, for the first three lines of the example (else the node is superposed on the text). You can see the tex file and it's compilation below. Now, I have several questions:

1/ I'm satisfied for the long and non-titled example but, for the titled example, tcolorbox doesn't include the title line in the three lines pushed (see Ex.4). So I want to push only two lines in this case. How can I do this ?

2/ I have a second problem for the broken example 'Ex.5', where one can see that at the break, the environment duplicates (automatically!) it's node of the title. This can be a good option for me, and now I want to examine two options: a/ The first one is to let the environment duplicate its node at break and then, how can I order at break the commands

    \parshape 4
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize

to let the behavior as the beginning of the environment ?

b/ The second option is to make this duplicate forbidden. What's the option that makes the behaviour of this example node as usual, i.e. breakable but not duplicate the title at break ?

I give my tex file...

    \documentclass{book}

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

    \usepackage{polyglossia}
    \setmainlanguage[numerals=maghrib]{arabic}
    \setotherlanguage{english}
    \usepackage{fontspec}
    \setmainfont{Times New Roman}
    \setsansfont{Arial}
    \setmonofont{Courier New}
    \newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

    \usepackage{polyglossia}
    \setdefaultlanguage{arabic}

    \newcounter{example}[section]
    \renewcommand{\theexample}{\arabic{example}}
    \newcommand{\examplelabel}{%
    {\bfseries\large
    Ex.
    \LR{\theexample}
    }}

    \newenvironment{example_small}[1][]{%
    \refstepcounter{example}%
    \begin{tcolorbox}[enhanced,breakable,
    colback=white,  arc=0mm,
    width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
    top=1mm, bottom=1mm, left=0mm, right=0mm,
    colbacktitle=yellow, colframe=red, coltitle=black, title=#1,
    before upper={\vspace*{1.5mm}
    \parshape 3
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize
            },
    after upper app={\vspace*{1.5mm}},
    extrude right by=-5.5mm,
    overlay={%
    \node[text width=.09\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\examplelabel};}]}{%
    \end{tcolorbox}}

    \newenvironment{example}[1][]{%
    \refstepcounter{example}%
    \begin{tcolorbox}[enhanced,breakable,
    colback=white, colframe=red, arc=0mm,
    rightrule=0mm, leftrule=0mm,toprule=0mm,
    top=1mm, bottom=1mm, left=0mm, right=0mm,
    colbacktitle=green, coltitle=black, 
    title=#1,
    %title={\hspace*{2mm}#1},
    extrude right by=-5.5mm,
    before upper={\parshape 4
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \dimexpr \hsize-7mm\relax
            0pt \hsize},
    overlay={%
    \node[fill=yellow, draw=red, line width=1.5pt, below right, minimum height=3em, text width=.8cm, align=center] at ([xshift=-.1mm]frame.north east) {\examplelabel};
    \draw [red,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
    \draw [red,line width=.5mm]([yshift=.25mm]frame.north west)--+(\linewidth,0);}
    ]}{%
    \end{tcolorbox}}


    \begin{document}
    \noindent
    \LR{
     In this document, the text would be written in arabic, a right-to-left language
    }

    \begin{example_small}
    \LR{
    A one-line example
    }
    \end{example_small}

    \begin{example_small} 
    \LR{
    A two-lines example
    }
    \\
    \LR{
    A two-lines example
    }
    \end{example_small}

    \begin{example}
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \\
    \LR{
    A general example
    }
    \end{example} 

    \begin{example}[\hspace*{2.5mm}\LR{Title of the example}]
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \LR{
    A general titled example
    }
    \\
    \end{example} 


    \begin{example}[\hspace*{2.5mm}\LR{A broken example}]
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    %%\vspace*{10cm}
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\ 
    \LR{
    An example artificially broken
    }
    \\
    \LR{
    An example artificially broken
    }
    \end{example} 


    \end{document}

And the compilation obtained

enter image description here enter image description here

1 Answer 1

1

I have modified your example to answer the questions.

For the first question, the before upper code is changed if a title is present, see code={\ifstrempty ...

For the second question, the underlay is changed in dependency of the break state. I also changed overlay to underlay, because it is nearly the same thing but you can use it several times for the same box and the code it added and not replaced.

It would not be possible to have a \parshape at break point, but it is possible to remove the duplicate box:

\documentclass{book}

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

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

\usepackage{polyglossia}
\setdefaultlanguage{arabic}

\newcounter{example}[section]
\renewcommand{\theexample}{\arabic{example}}
\newcommand{\examplelabel}{%
{\bfseries\large
Ex.
\LR{\theexample}
}}

\newtcolorbox[use counter=example]{example_small}[1][]{enhanced jigsaw,breakable,
  colback=white,  arc=0mm,
  width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
  top=1mm, bottom=1mm, left=0mm, right=0mm,
  colbacktitle=yellow, colframe=red, coltitle=black, title=#1,
  before upper={\vspace*{1.5mm}
  \parshape 3
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize
        },
  after upper app={\vspace*{1.5mm}},
  extrude right by=-5.5mm,
  overlay={%
    \node[text width=.09\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\examplelabel};}
}

\newtcolorbox[use counter=example]{example}[1][]{enhanced jigsaw,breakable,
  colback=white, colframe=red, arc=0mm,
  rightrule=0mm, leftrule=0mm,toprule=0mm,
  top=1mm, bottom=1mm, left=0mm, right=0mm,
  colbacktitle=green, coltitle=black,
  title=#1,
  extrude right by=-5.5mm,
  before upper={\parshape 4
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
  code={\ifstrempty{#1}{}{%
    \tcbset{
      before upper={\parshape 3
        0pt \dimexpr \hsize-7mm\relax
        0pt \dimexpr \hsize-7mm\relax
        0pt \hsize},
    }}},
  underlay unbroken and first={%
  \node[fill=yellow, draw=red, line width=1.5pt, below right, minimum height=3em, text width=.8cm, align=center] at ([xshift=-.1mm]frame.north east) {\examplelabel};
  \draw [red,line width=.5mm]([yshift=.25mm]frame.north west)--+(\linewidth,0);
  },
  underlay unbroken and last={%
  \draw [red,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
  },
}


\begin{document}
\noindent
\LR{
In this document, the text would be written in arabic, a right-to-left language
}

\begin{example_small}
\LR{
A one-line example
}
\end{example_small}

\begin{example_small}
\LR{
A two-lines example
}
\\
\LR{
A two-lines example
}
\end{example_small}

\begin{example}
\LR{
A general example
}
\\
\LR{
A general example
}
\\
\LR{
A general example
}
\\
\LR{
A general example
}
\end{example}

\begin{example}[\hspace*{2.5mm}\LR{Title of the example}]
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\LR{
A general titled example
}
\\
\end{example}


\begin{example}[\hspace*{2.5mm}\LR{A broken example}]
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
%%\vspace*{10cm}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\ 
\LR{
An example artificially broken
}
\\
\LR{
An example artificially broken
}
\end{example}


\end{document}

I also suggest to use enhanced jigsaw instead of jigsaw for your example (it depends on the previewer if the effect is visible).

enter image description here

enter image description here

3
  • It's what I wanted. I'll read the doc to understand the effect of the 'enhanced jigsaw' and the 'jigsaw' options. Many Thanks May 18, 2015 at 14:11
  • F Sturm. Almost all is ok, many thanks. I have a little problem : the red "frame.southwest" is duplicated at break. I unwant this because we think in this case that the example is finished. How can I remove this red line at the break ? Thank you May 19, 2015 at 17:05
  • @FaouziBellalouna I've modified the code in my answer to remove this line. I also replaced overlay by underlay, because for an unbroken box we need two code pieces added. May 20, 2015 at 7:49

You must log in to answer this question.

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