如何在圓內畫圓

如何在圓內畫圓

我正在學習如何使用 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}

在此輸入影像描述

相關內容