我想绘制嵌套的椭圆,每个椭圆显示一些文本(“函数 1”,...,“函数 4”,以可视化函数调用的依赖关系)。我想让文本根据相应的椭圆弯曲。以下是第一次尝试(不确定这是否是获得此图片的好方法)。当我编译它时(Ubuntu 12.10 上的 TeXLive 2012),它挂起了……出了什么问题?或者更确切地说:绘制这幅图的好方法是什么?
\documentclass{scrartcl}
\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={text along path, text={\texttt{Function
2}}}}] (0,0) ellipse (3.2cm and 1.6cm);% TODO:
% place the text on top of "Function 1"
\filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
{\texttt{Function 1}};
\end{tikzpicture}
\end{document}
答案1
摘自pgfmanual
:
在装饰中
text along path
,文本中的每个字符都以单独的格式排版\hbox
。 [...] 可以使用常规格式化命令(例如 \it、\bf 和 \color)来格式化文本, 可自定义的分隔符. 最初这些分隔符都是|
(强调添加)。
因此,在您的文本中,请|\tt|...
使用\texttt{...}
:
\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={text along path,
text={|\tt|Function 2},
},
}] (0,0) ellipse (3.2cm and 1.6cm);% TODO:
% place the text on top of "Function 1"
\filldraw[fill=gray!40, draw=gray!80] (0,0) ellipse (1.6cm and 0.8cm) node
{\texttt{Function 1}};
\end{tikzpicture}
\end{document}