TikZ 图片中的阿拉伯文节点

TikZ 图片中的阿拉伯文节点

我写了一份包含多种语言的文档,这些语言的书写方向不同。主要语言的方向是从左到右。我想用另一种语言(方向从右到左)写一个树形图。

首先我尝试这个:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{Arabic}
\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}
\end{Arabic}

\end{document}

并且我看到文本以错误的方向显示并且 tikzpicture 以从左到右的方向显示。 在此处输入图片描述

其次我尝试这个

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
\begin{Arabic}
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{Arabic}
\end{tikzpicture}

\end{document}

我得到了与上面相同的结果。

第三次我尝试这个

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{Arabic}
\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {\RL{الۡأَصۡلُ}}
        child {node {\RL{الۡفَرۡعُ الۡأَوَّلُ}}}
        child {node {\RL{الۡفَرۡعُ الثَّانِيۡ}}
            child {node {\RL{فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}}
            child {node {\RL{فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}}
    };
\end{tikzpicture}
\end{Arabic}

\end{document}

我以正确的方向显示文本,但 tikzpicture 仍然以从左到右的方向显示。 在此处输入图片描述

最后,我尝试进行测试,将默认语言从右到左更改:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{arabic} % Arabic Language, Right to Left Direction
\setotherlanguage{bahasai} % Indonesian Language, Left to Right Direction
\begin{document}

لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node {الۡأَصۡلُ}
        child {node {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node {الۡفَرۡعُ الثَّانِيۡ}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}

\end{document}

令我惊讶的是,文本和 tikzpicture 环境都显示不正确,与第一次和第二次测试的结果相似。

有什么解决方案可以让我让文本和 tikzpicture 环境都从右到左显示吗?谢谢。

答案1

TikZ 图片中的阿拉伯文节点

你可以定义一个arabic nodeTikZ 风格:

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

完成的示例:

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:
\end{Arabic}

\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node[arabic node] {الۡأَصۡلُ}
        child {node[arabic node] {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node[arabic node] {الۡفَرۡعُ الثَّانِيۡ}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}

\end{document}

RTL/LTR 环境中 tikzpicture 存在错误

有关tikzpicture显示的环境从右到左方向,看来 XeTeX 的 RTL/LTR 机制破坏了tikzpicture环境(一种错误……)。当您取消注释arabic其他语言时,以下文档会发生变化:

\documentclass[11pt,a4paper]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{english}
%\setotherlanguage{arabic} % Arabic Language, Right to Left Direction
\begin{document}
A
\begin{tikzpicture}
\fill[cyan] (0,0) rectangle (2,1);
\end{tikzpicture}
B
\end{document}

解决方法

作为解决方法,你可以把你的放在tikzpicture一个框中(通过\makebox):

\documentclass[a4paper,12pt,fleqn]{article}
\usepackage[no-math,quiet]{fontspec}
\setmainfont[Ligatures=TeX]{Linux Libertine O}
\newfontfamily\arabicfont[Script=Arabic,Mapping=arabicdigits]{Amiri}
\usepackage{tikz}
\usepackage[quiet]{polyglossia}
\setmainlanguage{bahasai} % Indonesian Language, Left to Right Direction
\setotherlanguage{arabic} % Arabic Language, Right to Left Direction

\tikzset{
  arabic node/.style={
    execute at begin node={\Arabic},
    execute at end node={\endArabic},
  },
}

\begin{document}

\begin{Arabic}
لَاحِظِ الصُّوۡرَةَ الشَّجَرِيَّةَ التَّالِيَةَ:

\makebox{\begin{tikzpicture}
    [parent anchor=west,child anchor=east,grow=west,
     sibling distance=15mm, level distance=35mm
    ]
    \node[arabic node] {الۡأَصۡلُ}
        child {node[arabic node] {الۡفَرۡعُ الۡأَوَّلُ}}
        child {node[arabic node] {الۡفَرۡعُ الثَّانِيۡ}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الۡأَوَّلُ}}
            child {node[arabic node] {فَرۡعُ الۡفَرۡعِ الۡأَوَّلِ الثَّانِيۡ}}
    };
\end{tikzpicture}}
\end{Arabic}

\end{document}

相关内容