如何在 Tikz 中沿圆圈放置标签

如何在 Tikz 中沿圆圈放置标签

我想在 Tikz 中沿圆圈放置标签。但是,在下面的示例中,标签距离其顶点相当远。有没有办法改善它们的放置位置?

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}


\begin{document}
    \begin{tikzpicture}
            \draw[line width=0.07mm] circle(1cm);
            \draw[line width=0.02mm] (0,0) -- (1,0) node[anchor=west]{$0$};
            \draw[line width=0.02mm]  (0,0) -- ({-1+sqrt(5))/4},{sqrt(10+2*sqrt(5))/4}) node[anchor=south west]{A};
            \draw[line width=0.02mm]  (0,0) -- ({-1-sqrt(5))/4},{sqrt(10-2*sqrt(5))/4}) node[anchor=south east]{B};
            \draw[line width=0.02mm]  (0,0) -- ({-1-sqrt(5))/4},{-sqrt(10-2*sqrt(5))/4}) node[anchor=north east]{C};            
            \draw[line width=0.02mm]  (0,0) -- ({-1+sqrt(5))/4},{-sqrt(10+2*sqrt(5))/4}) node[anchor=north west]{D};
            \draw[line width=0.3mm] (1,0) -- ({-1+sqrt(5))/4},{sqrt(10+2*sqrt(5))/4}) -- ({-1-sqrt(5))/4},{sqrt(10-2*sqrt(5))/4})
                    -- ({-1-sqrt(5))/4},{-sqrt(10-2*sqrt(5))/4}) -- ({-1+sqrt(5))/4},{-sqrt(10+2*sqrt(5))/4}) -- (1,0);
    \end{tikzpicture}
\end{document}

答案1

为什么不使用极坐标和周长锚点?放置节点时,如果您指定anchor=N锚点,则该点将是N从节点以一定角度离开的点 --- 因此,您可以将 放置A,例如,使锚点180+72紧靠在圆上。

然后使用foreach

\documentclass{article}

\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
    \tikzset{narrow/.style={inner sep=3pt}}
    \draw [] (0,0) circle[radius=1cm];
    \foreach \ang/\lab [evaluate=\ang as \anc using \ang+180]
        in {0/0, 72/A, 144/B, -144/C, -72/D}
        \draw [ultra thin] (0,0) -- (\ang:1) node[narrow, anchor=\anc]{\lab};
    \draw [thick] (0:1) foreach \ang in {72, 144, -144, -72}
        { -- (\ang:1)} --cycle;
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}


\begin{document}
    \begin{tikzpicture}[label distance=-4pt,]
            \draw[line width=0.07mm] circle(1cm);
            \draw[line width=0.02mm] (0,0) -- (1,0) node[anchor=west]{$0$};
            \draw[line width=0.02mm]  (0,0) -- ({-1+sqrt(5))/4},{sqrt(10+2*sqrt(5))/4}) node[anchor=south west]{A};
            \draw[line width=0.02mm]  (0,0) -- ({-1-sqrt(5))/4},{sqrt(10-2*sqrt(5))/4}) node[anchor=south east, label=120:q, outer sep=0pt, inner sep=0pt]{};
            \draw[line width=0.02mm]  (0,0) -- ({-1-sqrt(5))/4},{-sqrt(10-2*sqrt(5))/4}) node[anchor=north east]{C};            
            \draw[line width=0.02mm]  (0,0) -- ({-1+sqrt(5))/4},{-sqrt(10+2*sqrt(5))/4}) node[anchor=north west]{D};
            \draw[line width=0.3mm] (1,0) -- ({-1+sqrt(5))/4},{sqrt(10+2*sqrt(5))/4}) -- ({-1-sqrt(5))/4},{sqrt(10-2*sqrt(5))/4})
                    -- ({-1-sqrt(5))/4},{-sqrt(10-2*sqrt(5))/4}) -- ({-1+sqrt(5))/4},{-sqrt(10+2*sqrt(5))/4}) -- (1,0);
    \end{tikzpicture}
\end{document}

答案3

相同的图表,但节点更接近图纸

Tikz支持极坐标:

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}


\begin{document}
    \begin{tikzpicture}
            \draw[line width=0.07mm] circle(1cm);
            \draw[line width=0.02mm] (0,0) -- (0:1);
            \draw[line width=0.02mm] (0,0) -- (72:1);
            \draw[line width=0.02mm] (0,0) -- (144:1);
            \draw[line width=0.02mm] (0,0) -- (216:1);
            \draw[line width=0.02mm] (0,0) -- (288:1);
            \draw[line width=0.3mm] (0:1) -- (72:1) -- (144:1) -- (216:1) -- (288:1) -- cycle;
            \node at (0:1.15) {\(0\)};
            \node at (72:1.2) {\(A\)};
            \node at (144:1.2) {\(B\)};
            \node at (216:1.25) {\(C\)};
            \node at (288:1.2) {\(D\)};
    \end{tikzpicture}
\end{document}

语法是(angle:radius)。使用这个,你可以精确地选择节点与原点的距离,从而确定它与圆的距离。我只是尝试了不同的节点半径,直到它们靠近圆而不接触圆。这还有一个额外的好处,就是只要你知道 360/5 = 72,你就可以省去所有必须做的数学运算。

相关内容