如何使用 Tikzstyle 和 Tcolorbox 制作三种颜色的矩形

如何使用 Tikzstyle 和 Tcolorbox 制作三种颜色的矩形

我要用阿拉伯语写一本书,背景是页边空白处带有两种颜色条纹的图像。我将其包含在文档中,没有任何问题,使用了 bachground 包。但是我的定理和例子等的标签也写在页边空白处,当它叠加在条纹上时,效果不是很漂亮,因为它的颜色是白色的。所以我想让定理的矩形和类似的矩形与背景颜色相同,条纹也相同,蓝色在“黄色”之后是白色(好像背景是反转的,示例在背景中,图像在文档中!)。我给出了原始图像(用作背景)和将此图像作为背景获得的文档示例。我想获得与背景颜色相同的 Tikz 矩形,一个蓝色扇区,一个白色扇区,一个黄色扇区。 在此处输入图片描述 在此处输入图片描述

我给出了 tex 文档。请注意,给出的方框尺寸是经验性的,并不重要,因为我现在不知道条纹的确切位置。编辑稍后会将其发送给我。

\documentclass[14pt,twoside]{book}

\usepackage{extsizes}

\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}% 

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\backgroundsetup{scale=1,opacity=1,angle=0,contents={\includegraphics[width=\paperwidth,height=\paperheight]{R3}}}
\BgThispage

\tikzstyle{whitebox} =
[draw=white, thick, scale=.707, fill=white,% 
    line width=0.3pt, text=black, rectangle,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter, 
number within=section,
number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]{%
enhanced,
left=-5pt,
right=-5pt,
colback=gray!40,
colframe=white,
top=1mm,
bottom=8.5mm,
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,
label={#2},
overlay unbroken and first={%
\node[whitebox]
at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
{\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
\hline
\rule{0pt}{2ex}
\mbox{Ex}
\\
\mbox{\large\thetcbcounter}
\rule{0pt}{1.5ex}
\end{array}$}}};},
breakable,
before=\par\smallskip\centering,
width=\textwidth,       %%% change the width here.
arc=0pt,outer arc=0pt,
extrude right by=5pt,
extrude left by=5pt,
#1}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode}
\end{example}
\end{document}

好的文件。 在此处输入图片描述

更新文档以包含偶数/奇数命令来插入不同的背景

它使用 Thomas F. Sturm 介绍的方法。我的目标是只在偶数页上使用它,在奇数页上,使用“boxwhite”真正白色,而不是黄色和蓝色。

我给出了偶数/奇数得到的结果。

在此处输入图片描述

在此处输入图片描述

守则

\documentclass[14pt,twoside]{book}

\usepackage{extsizes}

\usepackage{amsmath,amssymb,lipsum}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\definecolor{myBlue}{rgb}{0.388235,0.454902,0.525490}
\definecolor{myYellow}{rgb}{0.643137,0.564706,0.388235}

\usepackage{background}
\usepackage{ifthen}
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}%
{
\backgroundsetup{
%position={0,0},
scale=1,
opacity=1,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{L3}
  }%
}
}%
{
\backgroundsetup{
%position={0,1},
scale=1,
opacity=1,
angle=0,
contents={%
 \begin{tikzpicture}
    \path (0,0)--(-\textwidth-20mm,0);
    \draw[line width=5mm,myBlue](0,0)--++(0,\paperheight);
    \draw[line width=5mm,myYellow](0.7,0)--++(0,\paperheight);
    \end{tikzpicture}
      }%
}
}%
\BgMaterial}

\tikzstyle{whitebox} =
 [%draw=white,
    thick, scale=.707,%fill=white, fill opacity=0.6,%
    line width=0.3pt, text=black, rectangle, inner sep=3mm,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter,
    number within=section,
    number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]%
{%
  enhanced,
  left=-5pt,
  right=-5pt,
  colback=gray!40,
  colframe=white,
  top=1mm,
  bottom=8.5mm,
  enlarge top by=\baselineskip/2+1mm,
  fontupper=\normalsize,
  label={#2},
  overlay unbroken and first={%
    \pgfdeclarelayer{background}
    \pgfsetlayers{background,main}
    \node[whitebox] (B)
      at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
      {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
      \hline
      \rule{0pt}{2ex}
     \mbox{Ex}
      \\
      \mbox{\large\thetcbcounter}
      \rule{0pt}{1.5ex}
      \end{array}$}}};
    \begin{pgfonlayer}{background}
    \draw [line width=5mm,myYellow]([xshift=3.5mm]frame.south east|-B.south)--      ([xshift=3.5mm]frame.north east|-B.north);
    \draw [line width=5mm,myBlue]([xshift=10.5mm]frame.south east|-B.south)--   ([xshift=10.5mm]frame.north east|-B.north);
    \end{pgfonlayer}
    },
  breakable,
  before=\par\smallskip\centering,
  width=\textwidth,       %%% change the width here.
  arc=0pt,outer arc=0pt,
  extrude right by=5pt,
  extrude left by=5pt,
  enlarge top at break by=0mm,pad at break=2mm,
  #1%
}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\newpage
\begin{example}{lab:exam:2}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\end{document}

我发布了第二个更新,其中包含页面的精确尺寸和背景图像。我的问题是如何准确确定底图(偶数页)的尺寸(这里是经验性的……),以便准确叠加底图和背景?……在这里找到 .tex 文件及其汇编,以及背景图像。框中使用的阿拉伯语单词 (مثال) 表示示例。

tex 文件

\documentclass[12pt]{书}

\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}

\usepackage{changepage}%<----------------- To check even / odd
\strictpagecheck

\usepackage{lipsum}
\usepackage{array}

\usepackage[paperwidth=170mm,paperheight=240mm,hmargin=2.5cm,vmargin=2.5cm,headheight=14pt,includefoot]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
    \newfontfamily\englishfont[Scale=1]{Times New Roman}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}


\definecolor{myBlue}{rgb}{0.388235,0.454902,0.525490}
\definecolor{myYellow}{rgb}{0.643137,0.564706,0.388235}

    \usepackage{background}
    \usepackage{ifthen}
    \AddEverypageHook{%
    \ifthenelse{\isodd{\value{page}}}%
    {
    \backgroundsetup{
    %position={0,0},
    scale=1,
    opacity=1,
    angle=0,
    contents={%
      \includegraphics[width=\paperwidth,height=\paperheight]{L}
      }%
    }
    }%
    {
    \backgroundsetup{
    %position={0,1},
    scale=1,
    opacity=1,
    angle=0,
    contents={%
      \includegraphics[width=\paperwidth,height=\paperheight]{R}
          }%
    }
    }%
    \BgMaterial}



\tikzstyle{whitebox} =
[%draw=white, 
thick, scale=.75, %fill=white,% 
line width=0.3pt, text=black, rectangle,
font=\Large,
left, minimum height=.5cm, minimum width=1.9cm]


\tikzstyle{yellowbox} =
[fill=myYellow, inner sep=1.5pt, 
thick, scale=.74, draw=myBlue,
line width=1pt, text=black, rectangle,
font=\Large,left]


\newcounter{example}

\newtcolorbox[auto counter,number within=section,number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]{%
enhanced,top=0mm,left=-5pt,right=-5pt,enlarge top by=\baselineskip/2+1mm,enlarge top at break by=0mm, pad at break=2mm,fontupper=\normalsize,
check odd page,% <---------------------------------
overlay unbroken and first={%
 \pgfdeclarelayer{background}
 \pgfsetlayers{background,main}
 \ifoddpage
 \node[yellowbox] (B)
 at ([xshift=12mm,yshift=-.58cm]frame.north east)
    {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
    \hline
    \rule{0pt}{2ex}
    \mbox{\RL{مثال}}
    \\
    \mbox{\Large\thetcbcounter}
    \rule{0pt}{1.5ex}
    \end{array}$}}};
 \else    
 \node[whitebox] (B)
 at ([xshift=2cm,yshift=-.73cm]frame.north east)
      {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
    \hline
    \rule{0pt}{2ex}
    \mbox{\RL{مثال}}
    \\
    \mbox{\Large\thetcbcounter}
    \rule{0pt}{1.5ex}
    \end{array}$}}};
 \begin{pgfonlayer}{background}
        \draw [line width=4.7mm,myYellow]([xshift=10mm,yshift=.5mm]frame.south east|-B.south)--             ([xshift=10mm,yshift=.5mm]frame.north east|-B.north);
    \draw [line width=4.7mm,myBlue]([xshift=16mm,yshift=.5mm]frame.south east|-B.south)--                  ([xshift=16mm,yshift=.5mm]frame.north east|-B.north);
 \end{pgfonlayer}
    \fi%
    },
breakable,before=\par\smallskip\vspace{-10pt}\centering,arc=0pt,outer arc=0pt,colframe=white,colback=white,
width=\textwidth, borderline north={2pt}{-3pt}{myBlue},borderline south={2pt}{5pt}{myBlue},
label={#2},
#1}




\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{\lipsum[1]}
\end{example}
\newpage
\begin{example}{lab:exam:2}
\LR{\lipsum[1]}
\end{example}
\end{document}

获得的pdf文件:

在此处输入图片描述

在此处输入图片描述

背景图像..

在此处输入图片描述

在此处输入图片描述

答案1

正如我现在所看到的,我的答案与最初打算回答的问题有点偏差。不过,我觉得反转颜色的想法很好,如果你不介意的话,我会把答案留给未来寻找类似答案的读者。

我必须模拟缺失的R3背景图片。因此,您必须根据实际应用调整以下长度设置。我的情况如下:

在此处输入图片描述

whitebox稍微调整了一下(我删除了颜色white)并添加了一个underlay设置tcolorboxunderlay包含反转的彩色条纹。

我使用了underlay,因为它独立于overlay仅为第一页和未间断的页面设置的。

最终的代码如下:

\documentclass[14pt,twoside]{book}

\usepackage{extsizes}

\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\backgroundsetup{scale=1,opacity=1,angle=0,contents={%
  %\includegraphics[width=\paperwidth,height=\paperheight]{R3}}
  % Mock up, because I do not have the R3 image
  \begin{tikzpicture}
    \path (0,0)--(-\textwidth-20mm,0);
    \draw[line width=5mm,blue!25!gray](0,0)--++(0,\paperheight);
    \draw[line width=5mm,yellow!25!gray](0.7,0)--++(0,\paperheight);
    \end{tikzpicture}}%
}
\BgThispage

\tikzstyle{whitebox} =
 [%draw=white,
    thick, scale=.707,% fill=white,%
    line width=0.3pt, text=black, rectangle,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter,
    number within=section,
    number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]%
{%
  enhanced,
  left=-5pt,
  right=-5pt,
  colback=gray!40,
  colframe=white,
  top=1mm,
  bottom=8.5mm,
  enlarge top by=\baselineskip/2+1mm,
  fontupper=\normalsize,
  label={#2},
  underlay={%
    \draw [line width=5mm,yellow!25!gray]([xshift=3.5mm]frame.south east)--([xshift=3.5mm]frame.north east);
    \draw [line width=5mm,blue!25!gray]([xshift=10.5mm]frame.south east)--([xshift=10.5mm]frame.north east);
  },
  overlay unbroken and first={%
    \node[whitebox]
    at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
    {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
    \hline
    \rule{0pt}{2ex}
    \mbox{Ex}
    \\
    \mbox{\large\thetcbcounter}
    \rule{0pt}{1.5ex}
    \end{array}$}}};},
  breakable,
  before=\par\smallskip\centering,
  width=\textwidth,       %%% change the width here.
  arc=0pt,outer arc=0pt,
  extrude right by=5pt,
  extrude left by=5pt,
  enlarge top at break by=0mm,pad at break=2mm,
  #1%
}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode}
\end{example}
\end{document}

作为一种变体,可以向框中添加一些半透明的白色Ex。这样可以得到:

在此处输入图片描述

代码如下:

\documentclass[14pt,twoside]{book}

\usepackage{extsizes}

\usepackage{amsmath,amssymb,lipsum}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\backgroundsetup{scale=1,opacity=1,angle=0,contents={%
  %\includegraphics[width=\paperwidth,height=\paperheight]{R3}}
  % Mock up, because I do not have the R3 image
  \begin{tikzpicture}
    \path (0,0)--(-\textwidth-20mm,0);
    \draw[line width=5mm,blue!25!gray](0,0)--++(0,\paperheight);
    \draw[line width=5mm,yellow!25!gray](0.7,0)--++(0,\paperheight);
    \end{tikzpicture}}%
}
\BgThispage

\tikzstyle{whitebox} =
 [%draw=white,
    thick, scale=.707,fill=white, fill opacity=0.6,%
    line width=0.3pt, text=black, rectangle, inner sep=3mm,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter,
    number within=section,
    number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]%
{%
  enhanced,
  left=-5pt,
  right=-5pt,
  colback=gray!40,
  colframe=white,
  top=1mm,
  bottom=8.5mm,
  enlarge top by=\baselineskip/2+1mm,
  fontupper=\normalsize,
  label={#2},
  underlay={%
    \draw [line width=5mm,yellow!25!gray]([xshift=3.5mm]frame.south east)--([xshift=3.5mm]frame.north east);
    \draw [line width=5mm,blue!25!gray]([xshift=10.5mm]frame.south east)--([xshift=10.5mm]frame.north east);
  },
  overlay unbroken and first={%
    \node[whitebox]
    at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
    {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
    \hline
    \rule{0pt}{2ex}
    \mbox{Ex}
    \\
    \mbox{\large\thetcbcounter}
    \rule{0pt}{1.5ex}
    \end{array}$}}};},
  breakable,
  before=\par\smallskip\centering,
  width=\textwidth,       %%% change the width here.
  arc=0pt,outer arc=0pt,
  extrude right by=5pt,
  extrude left by=5pt,
  enlarge top at break by=0mm,pad at break=2mm,
  #1%
}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\end{document}

更新:

根据原帖作者的要求,这里做了一个修改,只反转了 下方的颜色whitebox。这里underlay不需要 。

在此处输入图片描述

代码如下:

\documentclass[14pt,twoside]{book}

\usepackage{extsizes}

\usepackage{amsmath,amssymb,lipsum}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\definecolor{myBlue}{rgb}{0.388235,0.454902,0.525490}
\definecolor{myYellow}{rgb}{0.643137,0.564706,0.388235}

\backgroundsetup{scale=1,opacity=1,angle=0,contents={%
  %\includegraphics[width=\paperwidth,height=\paperheight]{R3}}
  % Mock up, because I do not have the R3 image
  \begin{tikzpicture}
    \path (0,0)--(-\textwidth-20mm,0);
    \draw[line width=5mm,myBlue](0,0)--++(0,\paperheight);
    \draw[line width=5mm,myYellow](0.7,0)--++(0,\paperheight);
    \end{tikzpicture}}%
}
\BgThispage

\tikzstyle{whitebox} =
 [%draw=white,
    thick, scale=.707,%fill=white, fill opacity=0.6,%
    line width=0.3pt, text=black, rectangle, inner sep=3mm,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter,
    number within=section,
    number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]%
{%
  enhanced,
  left=-5pt,
  right=-5pt,
  colback=gray!40,
  colframe=white,
  top=1mm,
  bottom=8.5mm,
  enlarge top by=\baselineskip/2+1mm,
  fontupper=\normalsize,
  label={#2},
  overlay unbroken and first={%
    \pgfdeclarelayer{background}
    \pgfsetlayers{background,main}
    \node[whitebox] (B)
      at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
      {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
      \hline
      \rule{0pt}{2ex}
      \mbox{Ex}
      \\
      \mbox{\large\thetcbcounter}
      \rule{0pt}{1.5ex}
      \end{array}$}}};
    \begin{pgfonlayer}{background}
    \draw [line width=5mm,myYellow]([xshift=3.5mm]frame.south east|-B.south)--([xshift=3.5mm]frame.north east|-B.north);
    \draw [line width=5mm,myBlue]([xshift=10.5mm]frame.south east|-B.south)--([xshift=10.5mm]frame.north east|-B.north);
    \end{pgfonlayer}
    },
  breakable,
  before=\par\smallskip\centering,
  width=\textwidth,       %%% change the width here.
  arc=0pt,outer arc=0pt,
  extrude right by=5pt,
  extrude left by=5pt,
  enlarge top at break by=0mm,pad at break=2mm,
  #1%
}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\end{document}

更新 2:

OP 的另一个要求是只为偶数页设置颜色切换。因此,我添加了包changepagecheck odd page密钥。所有更改都标记在下面的代码中,该代码会更改偶数页的颜色,并保持奇数页的标签框背景为白色:

\documentclass[14pt,twoside]{book}

\usepackage{changepage}%<----------------- To check even / odd
\strictpagecheck

\usepackage{extsizes}

\usepackage{amsmath,amssymb,lipsum}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}%

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\definecolor{myBlue}{rgb}{0.388235,0.454902,0.525490}
\definecolor{myYellow}{rgb}{0.643137,0.564706,0.388235}

\usepackage{background}
\usepackage{ifthen}
\AddEverypageHook{%
\ifthenelse{\isodd{\value{page}}}%
{
\backgroundsetup{
%position={0,0},
scale=1,
opacity=1,
angle=0,
contents={%
  \includegraphics[width=\paperwidth,height=\paperheight]{L3}
  }%
}
}%
{
\backgroundsetup{
%position={0,1},
scale=1,
opacity=1,
angle=0,
contents={%
 \begin{tikzpicture}
    \path (0,0)--(-\textwidth-20mm,0);
    \draw[line width=5mm,myBlue](0,0)--++(0,\paperheight);
    \draw[line width=5mm,myYellow](0.7,0)--++(0,\paperheight);
    \end{tikzpicture}
      }%
}
}%
\BgMaterial}

\tikzstyle{whitebox} =
 [%draw=white,
    thick, scale=.707,%fill=white, fill opacity=0.6,%
    line width=0.3pt, text=black, rectangle, inner sep=3mm,
    font=\Large,
    left, minimum height=.5cm, minimum width=1.9cm]

\newcounter{example}

\newtcolorbox[auto counter,
    number within=section,
    number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]%
{%
  enhanced,
  left=-5pt,
  right=-5pt,
  colback=gray!40,
  colframe=white,
  top=1mm,
  bottom=8.5mm,
  enlarge top by=\baselineskip/2+1mm,
  fontupper=\normalsize,
  label={#2},
  check odd page,% <---------------------------------
  overlay unbroken and first={%
    \pgfdeclarelayer{background}
    \pgfsetlayers{background,main}
    \node[whitebox] (B)
      at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
      {\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
      \hline
      \rule{0pt}{2ex}
     \mbox{Ex}
      \\
      \mbox{\large\thetcbcounter}
      \rule{0pt}{1.5ex}
      \end{array}$}}};
    \ifoddpage\else% <---------------------------------
    \begin{pgfonlayer}{background}
    \draw [line width=5mm,myYellow]([xshift=3.5mm]frame.south east|-B.south)--      ([xshift=3.5mm]frame.north east|-B.north);
    \draw [line width=5mm,myBlue]([xshift=10.5mm]frame.south east|-B.south)--   ([xshift=10.5mm]frame.north east|-B.north);
    \end{pgfonlayer}
    \fi%
    },
  breakable,
  before=\par\smallskip\centering,
  width=\textwidth,       %%% change the width here.
  arc=0pt,outer arc=0pt,
  extrude right by=5pt,
  extrude left by=5pt,
  enlarge top at break by=0mm,pad at break=2mm,
  #1%
}%

\begin{document}

\setcounter{section}{1}

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\newpage
\begin{example}{lab:exam:2}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode
\lipsum[1]}
\end{example}
\end{document}

答案2

正如我在评论中提到的,您可以使用\node[whitebox,draw=none,fill=none]...或者您可以将样式的draw=white和选项更改为和。fill=whitewhiteboxdraw=nonefill=none

请注意,设置样式的最新语法是

\tikzset{whitebox/.style={...}}

此外,该选项thick将被后面的选项覆盖line width=0.3pt

所以我建议使用

\tikzset{
  whitebox/.style={
    rectangle,
    draw=none, fill=none,
    scale=.707, line width=.3pt,
    text=black, font=\Large, left,
    minimum height=.5cm, minimum width=1.9cm
  }
}

在此处输入图片描述

代码:

\documentclass[14pt,twoside]{book}
\usepackage{extsizes}

\usepackage{amsmath,amssymb}
\usepackage[most]{tcolorbox}

\usepackage{array}

\usepackage[total={165mm,235mm},includefoot,includehead,headheight=14pt,centering,twoside]{geometry}% 

\usepackage[pages=some]{background}

\usepackage{polyglossia}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{english}
    \newfontfamily\arabicfont[Script=Arabic,Scale=1.2,AutoFakeSlant=-0.02]{Traditional Arabic}
\setmonofont{DejaVu Sans Mono}
\let\arabicfonttt\ttfamily
\setsansfont[Script=Arabic,Scale=1.5]{Traditional Arabic}

\backgroundsetup{scale=1,opacity=1,angle=0,contents={\includegraphics[width=\paperwidth,height=\paperheight]{R3}}}
\BgThispage

\tikzset{
  whitebox/.style={
    rectangle,
    draw=none, fill=none,
    scale=.707, line width=.3pt,
    text=black, font=\Large, left,
    minimum height=.5cm, minimum width=1.9cm
  }
}

\newcounter{example}

\newtcolorbox[auto counter, 
number within=section,
number freestyle={\noexpand\arabic{section}\noexpand\alph{\tcbcounter}}]{example}[2][]{%
enhanced,
left=-5pt,
right=-5pt,
colback=gray!40,
colframe=white,
top=1mm,
bottom=8.5mm,
enlarge top by=\baselineskip/2+1mm,
enlarge top at break by=0mm,pad at break=2mm,
fontupper=\normalsize,
label={#2},
overlay unbroken and first={%
\node[whitebox]
at ([xshift=1.5cm,yshift=-.9cm]frame.north east)
{\strut\RL{\setlength{\extrarowheight}{-30.5pt}\textbf{$\begin{array}{c}
\hline
\rule{0pt}{2ex}
\mbox{Ex}
\\
\mbox{\large\thetcbcounter}
\rule{0pt}{1.5ex}
\end{array}$}}};},
breakable,
before=\par\smallskip\centering,
width=\textwidth,       %%% change the width here.
arc=0pt,outer arc=0pt,
extrude right by=5pt,
extrude left by=5pt,
#1}%

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

\begin{example}{lab:exam:1}
\LR{The text of the example (labeled here Ex) is usually in arabic, in RightToLeft mode}
\end{example}
\end{document}

相关内容