![我需要删除部分编号和标题之间的空格,并将编号部分放在右侧](https://linux22.com/image/465545/%E6%88%91%E9%9C%80%E8%A6%81%E5%88%A0%E9%99%A4%E9%83%A8%E5%88%86%E7%BC%96%E5%8F%B7%E5%92%8C%E6%A0%87%E9%A2%98%E4%B9%8B%E9%97%B4%E7%9A%84%E7%A9%BA%E6%A0%BC%EF%BC%8C%E5%B9%B6%E5%B0%86%E7%BC%96%E5%8F%B7%E9%83%A8%E5%88%86%E6%94%BE%E5%9C%A8%E5%8F%B3%E4%BE%A7.png)
\documentclass[12pt,oneside, tikz, ignorerest=false]{book} \usepackage[paperwidth=210mm,paperheight=297mm,hmargin=0.5cm,top=10mm,bottom=23mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{mindmap}
\pagestyle{empty}
\usepackage{etoc}
%\usepackage{hyperref}% if links are wanted
\usepackage[pdfstartview=FitH,colorlinks=true,urlcolor=blue,linkcolor=red]{hyperref}
\usepackage{polyglossia}
\setotherlanguage{english}
\setmainlanguage[numerals=maghrib]{arabic}
\setotherlanguage{french}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Amiri}
\newfontfamily\frenchfont{Times New Roman}
\newfontfamily\fontb[Script=Arabic, Scale=0.9]{AlBattar}
\newfontfamily\fonta[Script=Arabic, Scale=1.2]{AlBattar}
\newfontfamily\ttfont[Script=Arabic, Scale=1.2]{AlBattar}
\newfontfamily\myfont[Script=Arabic,Scale=1.3]{Sakkal Majalla}
\newfontfamily\na[Script=Arabic,Scale=0.9]{Amiri}
\newfontfamily\naa[Script=Arabic,Scale=0.8]{Amiri}
\begin{document}
\newtoks\treetok
\newtoks\chaptertok
\newtoks\sectiontok
\newcommand*\treenode {} % just to check we don't overwrite something
\newcommand*\tmprotate {} % just to check we don't overwrite something
\newcommand*\tmpoption {} % just to check we don't overwrite something
\newcommand*\tmpstuff {} % just to check we don't overwrite something
\newcommand*\appendtotok[2]{% #1=toks variable, #2=macro, expands once #2
#1\expandafter\expandafter\expandafter{\expandafter\the\expandafter #1#2}}
\newcommand*{\appendchildtree}[3]{%
% this is to construct "t1 child [concept color= #3]{t2}" from #1=t1 and #2=t2
% t1 and t2 are two toks variable (not macros)
% #3 = for example teal!60
\edef\tmpstuff {\the#1 child [concept color = #3]{\the#2}}%
#1\expandafter {\tmpstuff }%
}
\newcounter{partco}
\etocsetstyle{chapter}
{}
{}
{
\toks0 \expandafter{\etocthelinkednumber}%
\toks2 \expandafter{\etocthelinkedname}%
\stepcounter{partco}%
\ifcase\value{partco}%
\or \def\tmpoption {}%
\def\tmprotate {[clockwise from = 120]}% first
\or \def\tmpoption {}%
\def\tmprotate {[clockwise from = 60]}% second
\else\def\tmpoption {\textarabic{}}%
\def\tmprotate {[counterclockwise from = 90]}% third and higher
\fi
% define the part node
\edef\treenode{node \tmpoption{\the\toks2} \tmprotate }%
% this is a starting point which will be filled it by the section children
\chaptertok\expandafter{\treenode}
}
{}
%\etocsetstyle{chapter}
% {\etocskipfirstprefix}
% {\appendchildtree\treetok\chaptertok}
% {\preparetreenode
% \chaptertok\expandafter{\treenode}}
% {\appendchildtree\treetok\chaptertok}
\etocsetstyle{section}
{}
{}
{\toks0 \expandafter{\etocthelinkednumber}%
\toks2 \expandafter{\etocthelinkedname }%
% define the section node
\edef\treenode {node {\the\toks2 \space\the\toks0}}
\sectiontok\expandafter{\treenode}%
% update current part tree with this section node, adding the correct color
\ifcase\value{partco}%
\or \appendchildtree\chaptertok\sectiontok {teal!30}% first
\or \appendchildtree\chaptertok\sectiontok {yellow!40}% second
\or \appendchildtree\chaptertok\sectiontok {red!80}
\else\appendchildtree\chaptertok\sectiontok {green!30}% third etc...
\fi }
% This updates the global tree with the data from the
% part and all its children sections
{\ifcase\value{partco}%
\or \appendchildtree\treetok\chaptertok {teal!60}% first
\or \appendchildtree\treetok\chaptertok {yellow!80}% second
\or \appendchildtree\treetok\chaptertok {red!80}% second
\else\appendchildtree\treetok\chaptertok {green!50}% third and next ...
\fi
}
\etocsettocstyle
{\treetok{\node{\textbf{\textarabic{العنواين الرئيسية}}} [clockwise from=45]}}
{\global\appendtotok\treetok{ ;}}
% The \global above is mandatory because etoc always typesets TOC inside a group
\tableofcontents
% \showthe\treetok % debugging
\begin{tikzpicture}[rotate=90, grow cyclic, text width=2cm,
align=flush center,
every node/.style=concept,
concept color=orange!60,
level 1/.style={level distance=5cm,sibling angle=90},
level 2/.style={rotate=-30,level distance=4cm,sibling angle=45}]
\the\treetok
\end{tikzpicture}
\chapter {\textarabic{العنوان الرئيسي الاول}}
\section {\textarabic{العنوان الاول}}
\section {العنوان الثاني }
\section {\textarabic{العنوان الثالث}}
\chapter {العنوان الرئيسي الثاني }
\section {العنوان الفرعي الاول}
\section {العنوان الثاني}
\section {العنوان الثاني}
\end{document}
答案1
我没有字体,所以我用以下方法测试了你的例子
% \newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Amiri}
% \newfontfamily\frenchfont{Times New Roman}
% \newfontfamily\fontb[Script=Arabic, Scale=0.9]{AlBattar}
% \newfontfamily\fonta[Script=Arabic, Scale=1.2]{AlBattar}
% \newfontfamily\ttfont[Script=Arabic, Scale=1.2]{AlBattar}
% \newfontfamily\myfont[Script=Arabic,Scale=1.3]{Sakkal Majalla}
% \newfontfamily\na[Script=Arabic,Scale=0.9]{Amiri}
% \newfontfamily\naa[Script=Arabic,Scale=0.8]{Amiri}
\newfontfamily\arabicfont[Script=Arabic,Scale=1.2]{Al Tarikh}
\newfontfamily\frenchfont{Times New Roman}
\newfontfamily\fontb[Script=Arabic, Scale=0.9]{Al Tarikh}
\newfontfamily\fonta[Script=Arabic, Scale=1.2]{Al Tarikh}
\newfontfamily\ttfont[Script=Arabic, Scale=1.2]{Al Tarikh}
\newfontfamily\myfont[Script=Arabic,Scale=1.3]{Al Tarikh}
\newfontfamily\na[Script=Arabic,Scale=0.9]{Al Tarikh}
\newfontfamily\naa[Script=Arabic,Scale=0.8]{Al Tarikh}
因为 Al Tarikh 在我的 mac os 上可用作系统字体。使用 XeLaTeX 编译时,我看到一些奇怪的字体规范警告:
Package fontspec Warning: Font "Al Tarikh" does not contain requested Script
(fontspec) "Arabic".
但输出可能没问题:(请注意,我不懂阿拉伯语,因此提前道歉)
命令如下
{\toks0 \expandafter{\etocthelinkednumber}%
\toks2 \expandafter{\etocthelinkedname }%
% define the section node
\edef\treenode {node {\the\toks2 \space\the\toks0}}
在\etocsetstyle{section}
块中。所以它已经说把数字放在右边,但也许它实际上应该在输出的相反位置,因为 LTR ?也许我的输出都是错的……请注意,这里的部分数字在下面,只是因为宽度恰好将它们移到了第二行。
因此,你可以尝试改变行中的顺序
\edef\treenode {node {\the\toks2 \space\the\toks0}}
并在这里使用一些 TikZ 语法来管理节点宽度。
另一个 fontspec 警告是
Missing character: There is no (U+200F) in font Al Tarikh Regular/OT:language
=dflt;!
最后,尝试 lualatex 给出了完全不同的输出:
不知道这是 TikZ 问题还是 RTL 渲染问题。
回到 xelatex 并整合这些评论:
我需要的是该部分之前的节号,而不是之后的节号
% define the section node
找到之后的行\edef\treenode {node {\the\toks2 \space\the\toks0}}
并将其替换为\edef\treenode {node {\the\toks0 \noexpand\hspace{3mm}\the\toks2}}
我添加了一个,
\hspace
以便您可以配置间距。这\noexpand
是因为这是一个\edef
但扩展必须延迟。另外,我假设您仍然希望 RTL 为节号1.1
,因此2.1
,,3.1
而不是1.1
,,1.2
。1.3
输出: