0

Is there any way to draw a circle from an inner to an outer diameter in a tikzpicture environment? I'd like to avoid using pstricks as in this answer.

As in this MWE, but without having to draw circle/node B above A (opacity=.5 added to show the "unwanted" inner part of circle A):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{%
    shapes.misc,    % additional shapes, such as rounded rectangles
    positioning,    % advanced positioning
}

\begin{document}
\begin{tikzpicture}[%
    roundnode/.style={circle, draw=black, fill=white, thick, inner sep=0em, opacity=1, fill opacity=1, draw opacity=1, font=\small},
    ]
    \node[roundnode, minimum size=15mm, fill=red!20] (nodeA) at (1, 0) {};
    \node[roundnode, minimum size=5mm, fill opacity=.5] (nodeB) at (1, 0) {B};  
\end{tikzpicture}
\end{document}

2 Answers 2

1

You need the [even odd rule] for \fill. Also, you need the radii for the nodes, which is half the minimum size.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{%
    shapes.misc,    % additional shapes, such as rounded rectangles
    positioning,    % advanced positioning
}

\begin{document}
\begin{tikzpicture}[%
    roundnode/.style={circle, draw=black, fill=white, thick, inner sep=0em, opacity=1, fill opacity=1, draw opacity=1, font=\small},
    ]
    \node[roundnode, minimum size=15mm] (nodeA) at (1, 0) {};
    %\path (nodeA.north);
    %\pgfgetlastxy{\xa}{\ya}
    \node[roundnode, minimum size=5mm] (nodeB) at (1, 0) {B};
    %\path (nodeB.north);
    %\pgfgetlastxy{\xb}{\yb}
    %\fill[even odd rule, red] (1,0) circle[radius=\yb] circle[radius=\ya];
    \fill[even odd rule, red] (1,0) circle[radius=7.5mm] circle[radius=2.5mm];
    
\end{tikzpicture}
\end{document}

demo

1
  • Many thanks! I'll try both answers tomorrow and respond afterwards.
    – JE_Muc
    Commented Dec 10, 2020 at 22:48
1

Using the fill even odd rule.

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \draw [thick,fill=red!20,even odd rule] (1,0) circle (7.5mm) (1,0) circle (2.5mm);
\end{tikzpicture}
\end{document}

output

1
  • Many thanks! I'll try both answers tomorrow and respond afterwards.
    – JE_Muc
    Commented Dec 10, 2020 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .