tikz:如何镜像路径装饰“沿路径的文本”?

tikz:如何镜像路径装饰“沿路径的文本”?

我想在 tikz 中创建带标签的嵌套椭圆。标签应遵循椭圆的形状。我使用 的路径修饰将pre标签移动到正确的位置,但我无法弄清楚:a):如何旋转它 [选项mirror 以错误的方式镜像它] 和 b):一旦我包含prepre length,其他选项(例如raisemirror)似乎不再受尊重。有人知道如何解决这个问题吗?

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathmorphing, decorations.text}

\begin{document}

\begin{tikzpicture}[decoration=zigzag]
  % ellipses
  \filldraw[fill=gray!10, draw=gray!80] (0,0) ellipse (6.4cm and 3.2cm);
  \filldraw[fill=gray!20, draw=gray!80] (0,0) ellipse (4.8cm and 2.4cm);
  \filldraw[fill=gray!30, draw=gray!80,
            postaction={decorate,
                        decoration={pre=moveto, pre length=3cm, raise=4mm, text along path, text={|\tt|Function 2}}}]
           (0,0) ellipse (3.2cm and 1.6cm);
  \filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
  {\texttt{Function 1}};
\end{tikzpicture}
\end{document}

答案1

你可以不装饰椭圆,而是装饰椭圆的一段圆弧,并且可以选择圆弧的方向。

在此处输入图片描述

\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{xcolor}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{decorations.pathmorphing, decorations.text}
\begin{document}
\begin{tikzpicture}[decoration=zigzag]
  % ellipses
  \filldraw[fill=gray!10, draw=gray!80] (0,0) ellipse (6.4cm and 3.2cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 4},
      text align=center,
    },
  }] (0,0) ++(110:6.4cm and 3.2cm) arc(110:70:6.4cm and 3.2cm);
  \filldraw[fill=gray!20, draw=gray!80] (0,0) ellipse (4.8cm and 2.4cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 3},
      text align=center,
    },
  }] (0,0) ++(110:4.8cm and 2.4cm) arc(110:70:4.8cm and 2.4cm);
  \filldraw[fill=gray!30, draw=gray!80] (0,0) ellipse (3.2cm and 1.6cm);
  \path[postaction={decorate,
    decoration={
      raise=-1em,
      text along path,
      text={|\tt|Function 2},
      text align=center,
    },
  }] (0,0) ++(110:3.2cm and 1.6cm) arc(110:70:3.2cm and 1.6cm);
  \filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
  {\texttt{Function 1}};
\end{tikzpicture}
\end{document}

相关内容