使用 xepersian 的 Latex tikz 章节

使用 xepersian 的 Latex tikz 章节

我想使用 xepersian 包自定义 tikz 章节。我将此包添加到本守则如下所示:

\documentclass[twoside]{book}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\usepackage{titletoc}
\usepackage{lipsum}

\usepackage{calc}

\usepackage[]{titlesec} 
\definecolor{yourcolor}{HTML}{008bb2}
\usepackage{xepersian}
\settextfont{Yas}
\colorlet{chpnumbercolor}{black}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{chpnumbercolor}{#2}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{chpnumbercolor}{#5}}}}
\makeatother

\titleformat{\chapter}[display]
  {\normalfont\color{yourcolor}}
  {\filleft\Huge\sffamily\bfseries\chaptertitlename\hspace*{2mm}%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=yourcolor,circle,text=white] {\thechapter};
  \end{tikzpicture}}
  {1ex}
  {\titlerule[1.5pt]\vspace*{5ex}\huge\sffamily\itshape}
  []

\titleformat{name=\chapter,numberless}[display]
  {\normalfont\color{yourcolor}}
  {}
  {1ex}
  {\vspace*{5ex}\huge\sffamily\itshape}
  []

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
    \noindent\hspace{-2cm}%
    \colorlet{chpnumbercolor}{white}%
    \begin{tikzpicture}
    \node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
        \color{white}%
        \begin{minipage}{8cm}%minipage trick
        \printcontents[chapters]{}{1}{}
        \end{minipage}};
    \end{tikzpicture}}

\begin{document}
\tableofcontents
\chapter{\rl{فصل اول}}
\startcontents[chapters]
%print minitoc
\printmyminitoc



\section{سکشن اول}
\lipsum[1]
\section{سکشن دوم}
\section{تست}
\section{الف ب پ}
\lipsum
\chapter{\rl{فصل دوم}}
\end{document}

但是数字不是波斯风格,并且单词“chapter”(波斯语“فصل”)没有出现。 在此处输入图片描述

答案1

首先请注意,miniTOC 内部\printmyminitoc命令是反转的(从左到右),您可以使用以下命令进行更正

\begin{RTL}
\printcontents[chapters]{}{1}{}
\end{RTL}

要获得波斯语形式,\thechapter你可以这样做\lr{\thechapter}


代码

\documentclass[twoside]{book}

\usepackage{tikz}
\usetikzlibrary{shadows.blur}
\usepackage{titletoc}
\usepackage{lipsum}

\usepackage{calc}

\usepackage[]{titlesec} 
\definecolor{yourcolor}{HTML}{008bb2}
\usepackage{xepersian}
\settextfont{Yas}
\colorlet{chpnumbercolor}{black}
\makeatletter
\let\oldl@chapter\l@chapter
\def\l@chapter#1#2{\oldl@chapter{#1}{\textcolor{chpnumbercolor}{ #2}}}

\let\old@dottedcontentsline\@dottedtocline
\def\@dottedtocline#1#2#3#4#5{%
\old@dottedcontentsline{#1}{#2}{#3}{#4}{{\textcolor{chpnumbercolor}{#5}}}}
\makeatother

\titleformat{\chapter}[display]
  {\normalfont\color{yourcolor}}
  {\filleft\Huge\sffamily\bfseries\chaptertitlename\hspace*{2mm}%
  \begin{tikzpicture}[baseline={([yshift=-.6ex]current bounding box.center)}]
    \node[fill=yourcolor,circle,text=white] {\rl{\thechapter}};
  \end{tikzpicture}}
  {1ex}
  {\titlerule[1.5pt]\vspace*{5ex}\huge\sffamily\itshape}
  []

\titleformat{name=\chapter,numberless}[display]
  {\normalfont\color{yourcolor}}
  {}
  {1ex}
  {\vspace*{5ex}\huge\sffamily\itshape}
  []

%command to print the acutal minitoc
\newcommand{\printmyminitoc}{%
    \noindent\hspace{-2cm}%
    \colorlet{chpnumbercolor}{white}%
    \begin{tikzpicture}
    \node[rounded corners,align=left,fill=yourcolor, blur shadow={shadow blur steps=5}, inner sep=5mm]{%
        \color{white}%
        \begin{minipage}{8cm}%minipage trick
        \begin{RTL}
        \printcontents[chapters]{}{1}{}
        \end{RTL}
        \end{minipage}};
    \end{tikzpicture}}

\begin{document}
\tableofcontents
\chapter{\rl{فصل اول}}
\startcontents[chapters]
%print minitoc
\printmyminitoc



\section{سکشن اول}
\lipsum[1]
\section{سکشن دوم}
\section{تست}
\section{الف ب پ}
\lipsum
\chapter{\rl{فصل دوم}}
\end{document}

输出

在此处输入图片描述

相关内容