我正在学习如何使用 TikZ/PGF。我想画这幅画:
以下是我的开始:
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,}
\begin{document}
\begin{tikzpicture}
\node (sun) at (0,0) [circle, fill=yellow, radius=0.3cm]{};
\node (sunlabel) [above=0.08 of sun]{Sun};
\node (root) at (0,0) [draw, circle, radius=3cm]{};
\end{tikzpicture}
\end{document}
问题是第二个圆没有画出来。我不知道问题出在哪里。这个语法有效,但我不知道如何给圆命名以及如何用颜色填充圆。
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle [radius=.3cm, fill=yellow];
\draw (0,0) circle [radius=2cm];
\path[
%rotate=-15.2,
postaction={
decoration={
text along path,
text={%
OORT CLOUD
},
text align=center,
reverse path
},
decorate
}
]
(-27:2.2cm) arc (-27:210:2.2cm);
\end{tikzpicture}
\end{document}
答案1
您需要将重音字符放在括号中,circle label
因为 PGF 会将字符串拆分为标记,因此会将重音符号与字符拆分开来,从而导致奇怪的错误。
我将标签翻译成法语以强调这种行为(我不会说法语,所以我希望我没有犯太多错误)。
\documentclass[tikz]{standalone}
\usepackage[utf8]{inputenx}
\usetikzlibrary{decorations.text}
\begin{document}
\sffamily
\begin{tikzpicture}[
white,
ultra thick,
planet/.style = {draw,fill,circle,inner sep=#1},
circle label/.style = {
postaction={
decoration={
text along path,
text = {#1},
text align=center,
text color=white,
reverse path,
},
decorate,
}
}
]
\filldraw[black] (-7,-7) rectangle (7,8);
\node at (0,7.5) {\bfseries\Large Voisins les plus proches du soleil};
\path[circle label={Nuage d'Oort}] (0,-1.2) arc (-90:360-90:1.2);
\draw[dotted] (0,0) circle (1);
\foreach \i in {2,4,6} {
\path[circle label={\i\ Ann{é}e lumi{è}res}] (0,-\i-.2) arc (-90:360-90:\i+.2);
\draw (0,0) circle (\i);
}
\node[yellow,planet=3pt,label={above:Soleil}] at (0,0) {};
\node[red,planet=3pt,label={[text width=1.5cm,align=right]0:Proxima Centauri déc.\ 1917}] at (44:4.3) {};
\node[yellow,planet=4pt,label={[text width=2.5cm,align=center]90:Alpha Centauri déc.\ 1917}] at (50:4.3) {};
\node[red!50!black,planet=2pt,label={[text width=2.5cm,align=center]0:WISE 1049-5319 déc.\ 2013}] at (54:6.3) {};
\node[red!50!black,planet=2pt] at (57:6.3) {};
\node[red,planet=3pt,label={[text width=3cm,align=center]95:L'étoile de Bernard déc.\ 1916}] at (125:6) {};
\end{tikzpicture}
\end{document}
答案2
如果使用以下语法:
\draw [fill=yellow] (0,0) circle (0.3cm) node (sun) {};
然后事情就会按预期进行:
笔记:
- 我
draw=none
为太阳添加了一个,因为您可能不希望它周围有边框。 - 我将原始内容作为注释留给您,以便您能够看到差异。
代码:
\documentclass[border=2pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[frenchb]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric,arrows,positioning,fit,calc,}
\begin{document}
\begin{tikzpicture}
%\node (sun) at (0,0) [circle, fill=yellow, radius=0.3cm] {};
\draw [fill=yellow, draw=none] (0,0) circle (0.3cm)
node (sun) {};
\node (sunlabel) [above=0.08 of sun]{Sun};
%\node (root) at (0,0) [draw=red, circle, radius=3cm] {};
\draw [draw=red, ultra thick] (0,0) circle (3.0cm)
node (planet) {};
\end{tikzpicture}
\end{document}
答案3
使用 PSTricks 可以减少击键次数。
\documentclass[pstricks,border=12pt]{standalone}
\begin{document}
\begin{pspicture}(-2,-2)(2,2)
\pscircle*[linecolor=orange]{5pt}
\pscircle{2}
\end{pspicture}
\end{document}