考虑这个例子,它需要对节点进行一些手动调整:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[thick]
% Axes
\def\xmin{-4}\def\xmax{4}
\def\ymin{-3}\def\ymax{3}
\draw[->] (\xmin,0) -- (\xmax+0.2,0) node[right] {$q_1$};
\draw[->] (0,\ymin) -- (0,\ymax) node[above] {$q_2$};
% Shell
\draw[blue] (0,0) circle [x radius=\xmax-1, y radius=\ymax-1] node[below right=35] {$E$};
\draw[red] (0,0) circle [x radius=\xmax-0.5, y radius=\ymax-0.5] node[below right=55] {$E + \Delta E$};
\end{tikzpicture}
\end{document}
有没有一种聪明的方法可以将节点放在圆圈内/外,TikZ
以便它们自动重新定位,以防我稍后决定更改圆圈的大小?为了平息任何迂腐的抱怨,这里的“聪明”意味着尽可能简短、易读和灵活的语法。
答案1
下面我说明了两个选项。第一个选项需要做最多修改,因为它使用\node
s 来绘制椭圆,使用 alabel
来添加标签。
第二种使用极坐标来指定节点的位置。
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[thick]
% Axes
\def\xmin{-4}\def\xmax{4}
\def\ymin{-3}\def\ymax{3}
\draw[->] (\xmin,0) -- (\xmax+0.2,0) node[right] {$q_1$};
\draw[->] (0,\ymin) -- (0,\ymax) node[above] {$q_2$};
% Shell
\node[
blue,
draw,
ellipse,
inner sep=0pt, % not strictly necessary when the nodes are this large
minimum width=(\xmax-1)*2cm,
minimum height=(\ymax-1)*2cm,
label={[above left,blue]330:$E$}] {};
\node[
red,
draw,
ellipse,
inner sep=0pt, % not strictly necessary when the nodes are this large
minimum width=(\xmax-0.5)*2cm,
minimum height=(\ymax-0.5)*2cm,
label={[below right,red]330:$E+\Delta E$}] {};
\end{tikzpicture}
\begin{tikzpicture}[thick]
% Axes
\def\xmin{-4}\def\xmax{4}
\def\ymin{-3}\def\ymax{3}
\draw[->] (\xmin,0) -- (\xmax+0.2,0) node[right] {$q_1$};
\draw[->] (0,\ymin) -- (0,\ymax) node[above] {$q_2$};
% Shell
\draw[blue] (0,0) circle [x radius=\xmax-1, y radius=\ymax-1];
\node[above left,blue] at (315:\xmax-1 and \ymax-1) {$E$};
\draw[red] (0,0) circle [x radius=\xmax-0.5, y radius=\ymax-0.5];
\node[below right,red] at (315:\xmax-0.5 and \ymax-0.5) {$E + \Delta E$};
\end{tikzpicture}
\end{document}