2

I use tcolorbox in arabic document with polyglossia for theorems examples, and so. I put the titles of environments in tikz boxes what I put in the margin (in the right margin, the arabic is written in Right to Left mode) I want (essentially for "small" examples but for others too...) to obtain good alignments of the boxes and for the nodes. Say a box and a node of the same height. I do it by hand, because I don't understand how tcolorbox decide where to put exactly the node... I give an ECM..

The tex file

    \documentclass[14pt]{extbook}%

    \usepackage[most]{tcolorbox}

    \usepackage{array}

     \tikzstyle{titlenode} =
     [draw=blue, thick, scale=.7, fill=red,% 
    line width=1pt, text=black, rectangle,
    font=\Large,
    left, minimum height=1cm]

    \newcounter{example}

    \newtcolorbox[auto counter,
        number within=section,
        number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[1][]{%
    enhanced,top=0mm,left=0pt,right=0pt,enlarge top by=\baselineskip/2+1mm,enlarge top at break by=0mm,pad at break=2mm,fontupper=\normalsize,
      overlay unbroken and first={%
        \pgfdeclarelayer{background}
        \pgfsetlayers{background,main}
    \node[titlenode] (B)
            at ([xshift=5mm,yshift=-6.3mm]frame.north east)
          {\strut\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
        \hline
        \rule{0pt}{2ex}
        \mbox{Example}
        \\
        \mbox{\Large\thetcbcounter}
        \rule{0pt}{1.5ex}
        \end{array}$}};
        },
    breakable,before=\par\smallskip\vspace{-10pt}\centering,arc=0pt,outer arc=0pt,colframe=white,colback=white,
    width=\textwidth,
    borderline north={2pt}{-3pt}{yellow},borderline south={2pt}{4.6pt}{blue},
    before upper={\parshape 4
            0pt \dimexpr \hsize-2.5cm\relax
            0pt \dimexpr \hsize-2.5cm\relax
            0pt \dimexpr \hsize-2.5cm\relax
            0pt \hsize},
    #1}

    \newtcolorbox[use counter from=example]{texample}[2][]{
    enhanced,boxrule=0pt,minipage boxed title=140mm,left=0pt,right=0pt,top=5mm,
    attach boxed title to top right={xshift=-5mm,yshift=-3.8mm,yshifttext=-1mm},
    coltitle=black,
    boxed title style={
    left=5pt,
    right=5pt,
    enhanced,
    arc=0pt,outer arc=0pt,
    colframe=blue,
    colback=yellow,
    colbacktitle=black,
    },
    enlarge top by=\baselineskip/2+1mm,enlarge top at break by=0mm,pad at break=2mm,fontupper=\normalsize,
      overlay unbroken and first={%
        \pgfdeclarelayer{background}
        \pgfsetlayers{background,main}
    \node[titlenode] (B)
            at ([xshift=5mm,yshift=-2.6mm]frame.north east)
          {\strut\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
        \hline
        \rule{0pt}{2ex}
        \mbox{Example}
        \\
        \mbox{\Large\thetcbcounter}
        \rule{0pt}{1.5ex}
        \end{array}$}};
        },
    breakable,before=\par\smallskip\centering,arc=0pt,colframe=white,colback=white,width=\textwidth,borderline south={2pt}{5pt}{blue},
    before upper={\parshape 2
            0pt \dimexpr \hsize-2.5cm\relax
            0pt \hsize},
    title={\strut\textbf{#2}\strut},
    #1}


    \begin{document}
    \setcounter{section}{1}

    \begin{example}
    A first example
    \end{example} 

    \vspace*{1cm}
    \begin{example}
    A first example. Aligned bottom
    \vspace*{.57cm}
    \end{example} 


    \begin{texample}{Titled example}
    By the same, I want that the title node rectangle will be exactly aligned with the box of title.
    \end{texample} 


    \end{document}

and its compilation with xelatex

enter image description here

I want that the title node rectangle will be exactly superposed on the borderline north (in yellow). One can see in the example 1a that the box is too small, and I want to arrange it in the bottom too, so that the borderline south will be exactly superposed under the title box. I arrange it by hand in the example 1b, in the text of the box by the command \vspace*{.57cm}. I want to do this automatically, i.e. to obtain box and node with the same height. How can I do this ?

By the same, I want to obtain good alignments of the title node rectangle and the box of the title. Many thanks

  • a good example that can help you is given in page 32 doc tcolorbox – touhami May 8 '15 at 8:43
  • which doc? The last one 3.40 or 3.03 ? What's the subject of this example ? – Faouzi Bellalouna May 8 '15 at 12:29
  • I have 3.21, i will try to give you some help, but i am not free now, give me some time. – touhami May 8 '15 at 13:00
2

This may be helpful

\documentclass{book}

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

\usepackage{fontspec}
\setmainfont{Times New Roman}
\setsansfont{Arial}
\setmonofont{Courier New}
\newfontfamily{\arabicfont}[Script=Arabic,Scale=1.5]{Traditional Arabic}

\usepackage{polyglossia}
\setdefaultlanguage{arabic}

\newcommand{\testarab}{%
اللغة العربية لغة جميله
اللغة العربية لغة جميله
اللغة العربية لغة جميله
اللغة العربية لغة جميله
اللغة العربية لغة جميله}

\newcounter{example}[section]
\renewcommand{\theexample}{\thesection.\alph{example}}
\newcommand{\exemplelabel}{%
المثال
\LR{\theexample}}

% this
\newenvironment{example}[1][]{%
\refstepcounter{example}%
\begin{tcolorbox}[enhanced,breakable,
colback=white, colframe=red, arc=0mm,
width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
top=0mm, bottom=0mm, left=0mm, right=0mm,
colbacktitle=yellow, coltitle=black, title=#1,
overlay={%
\node[text width=.1\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\exemplelabel};}]}{%
\end{tcolorbox}}

% or this
\newenvironment{Example}[1][]{%
\refstepcounter{example}%
\begin{tcolorbox}[skin=enhancedmiddle,breakable,
colback=white, colframe=red, arc=0mm,
width=1.1\linewidth, rightrule=.1\linewidth, leftrule=0mm,
top=0mm, bottom=0mm, left=0mm, right=0mm,
colbacktitle=yellow, coltitle=black, title=#1,
overlay={%
\node[text width=.1\linewidth, align=center] at ([xshift=-.05\linewidth]frame.east) {\exemplelabel};
\draw [blue,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
\draw [blue,line width=.5mm]([yshift=-.25mm]frame.north west)--+(\linewidth,0);}
]}{%
\end{tcolorbox}}
%---------------------------------------------
\begin{document}
\testarab
\begin{example}[اللغة العربية]
\testarab
\end{example}

\begin{Example}[اللغة العربية]
\testarab
\end{Example}

\begin{example}
\testarab
\end{example}

\begin{Example}
\testarab
\end{Example}
\testarab

\end{document}

enter image description here

Edit For fixed height I am not sure but you can try this

% this
\newenvironment{example}[1][]{%
\refstepcounter{example}%
\begin{tcolorbox}[enhanced,breakable,
colback=white, colframe=red, arc=0mm,
rightrule=.5mm, leftrule=0mm,
top=0mm, bottom=0mm, left=0mm, right=0mm,
colbacktitle=yellow, coltitle=black, title=#1,
overlay={%
\node[fill=red, below right, minimum height=3em, text width=1cm, align=center] at ([xshift=-.1mm]frame.north east) {\exemplelabel};}]}{%
\end{tcolorbox}}

% or this
\newenvironment{Example}[1][]{%
\refstepcounter{example}%
\begin{tcolorbox}[skin=enhancedmiddle,breakable,
colback=white, colframe=red, arc=0mm,
rightrule=.5mm, leftrule=0mm,
top=0mm, bottom=0mm, left=0mm, right=0mm,
colbacktitle=yellow, coltitle=black, title=#1,
overlay={%
\node[fill=red, below right, minimum height=3em, text width=1cm, align=center] at ([xshift=-.1mm]frame.north east) {\exemplelabel};
\draw [blue,line width=.5mm]([yshift=.25mm]frame.south west)--+(\linewidth,0);
\draw [blue,line width=.5mm]([yshift=-.25mm]frame.north west)--+(\linewidth,0);}
]}{%
\end{tcolorbox}}
  • It seems very helpful....and beautiful as the arabic language. I'll test it and keep you inform about in the final form. Many thanks – Faouzi Bellalouna May 8 '15 at 22:03
  • One thing. if I have a long example.. some thing like \begin{example}[اللغة العربية] \testarab testarab testarab \end{example}... the height will be too great and wil not be good for a title... How can I obtain a node of fixed height in this case ...some thing like 2cm for example.. ? – Faouzi Bellalouna May 8 '15 at 22:41
  • @FaouziBellalouna I edit my answer – touhami May 9 '15 at 7:34
  • would you see please these new question I've opened, strongly related (et meme based on !) with this one... tex.stackexchange.com/questions/245494/… – Faouzi Bellalouna May 18 '15 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.