在 Tikz 中添加标签

在 Tikz 中添加标签

我尝试创建的图形如下:(我尝试制作与上图相同的图形,下图是我的,但似乎不一样) 在此处输入图片描述

我的代码:

\begin{center}
\begin{tikzpicture} [scale=0.5]
\draw [magenta, thick] circle [radius=2] (0,0) node[above]{$R$}--(150:4.5cm);
\draw [magenta, thick] (0,0)--(6,0);

\node [circle,fill=black] at (4.05,2) {};
\node [circle,fill=black] at (4.05,-2) {};
\draw [blue, thick] circle [radius=4.5];
\draw [blue, thick] (0,2)--(6,2) node[above]{$B$} ;
\draw [blue, thick] (0,-2)--(6,-2) node[above]{$A$} ;
\draw [black, thick] (5,0)--(5,2) node[below right]{$R$};
\draw [black, thick] (5,0)--(5,-2) node[above right]{$R$};
\end{tikzpicture}
\end{center}

那么我该如何改进才能画出跟上边一样的效果呢?谢谢!

答案1

您可以向节点添加标签,我建议在$A$$B$和的情况下这样做Planet,并且您可以将节点作为标签添加到路径,这可能更适合其他标签。

\documentclass[border=1mm, tikz]{standalone}

\begin{document}
\begin{tikzpicture}[scale=0.5]

% two nodes as labels to the same path
\draw[magenta, thick] circle[radius=2] (0,0) node[below]{Star} -- (150:4.5cm) node[pos=.6, above] {$a$};

\draw[magenta, thick] (0,0)--(8,0);

% labels to nodes (multiple labels per node possible)
\node[circle, fill=black, label={45:$A$}] at (4.05,2) {};
\node[circle, fill=black, label={45:$B$}, label={-45:Planet}] at (4.05,-2) {};

\draw[blue, thick] circle[radius=4.5];
\draw[blue, thick] (0,2) -- (8,2);
\draw[blue, thick] (0,-2) -- (8,-2);

% nodes as labels to paths
\draw[black, thick, <->] (7,0) -- (7,2) node[below right]{$R$};
\draw[black, thick, <->] (7,0) -- (7,-2) node[above right]{$R$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

代码稍微复杂一些,但是交叉点(黑点的位置)是由intersections库计算的。路径、节点和标签的样式也已确定。因此,它们可以轻松一致地适应所需的图像元素样式:

\documentclass[border=1mm, tikz]{standalone}
\usetikzlibrary{backgrounds,
                intersections,
                positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
    scale=0.5, 
    node distance = 1em,
dot/.style = {circle, fill=black, inner sep=3pt, 
              label=#1, node contents={}},
 np/.style args = {#1/#2}{draw=#1, name path=#2},
%
every label/.style = {inner sep=1pt},
every  path/.style = {draw, thick, line cap=round},
every edge quotes/.style = {auto, inner sep=1pt}
                        ]

% small circle and two labels
\draw[np=magenta/{}, fill=magenta!15]  
    (225:44mm) to [pos=0.3, "$a$" sloped] (0:0) 
                    circle[radius=2] node[above] {Star}
               -- ++ (7,0) coordinate (aux1);
% big circle, labels at intersections
\draw[np=blue/C] circle[radius=44mm];
\draw[np=blue/A] (0,+2) -- ++ (aux1);
\draw[np=blue/B] (0,-2) -- ++ (aux1);
% intersections
\scoped[on background layer]
{
\draw[name intersections={of=C and A, by=a}]    
    (a) node[dot=45:$A$];
\draw[name intersections={of=C and B, by=b}]
    (b) node[dot=45:$B$, label=-45:Planet];
}
% distances with labels 
\coordinate[left=of aux1] (aux2);
\draw[<->]  (a -| aux2) edge ["$R$"] (aux2)
            (aux2)      edge ["$R$"] (b-| aux2);
\end{tikzpicture}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容