4

I know that with TikZ, we can specify the radius of a circle when a \draw command is used, as in:

 \draw[fill] (1,2) circle (3pt);

But how does one indicate the radius when you draw the circle by means of a \node command, as in the following?

 \node[fill,circle,label=below left:$x$] at (1,2) {};

For example, suppose I want a 3pt radius of the circle in this:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
   \node[fill,circle,label=below left:$x$] at (1,2) {};
\end{tikzpicture}
\end{document}

I prefer to see two ways of doing this: one way that would apply just to the particular (filled) circle, and a second way that could be used globally for the entire picture.

  • You can use minimum width=3pt to set a minimal width of 3pt. However, the node may be larger than that. You could use scale=0.3 or so to scale it down. – user121799 Aug 13 '18 at 22:18
  • Copy directly from manual: \draw (0,-2) node[minimum size=2cm,draw,circle] {circle}; – hpekristiansen Aug 13 '18 at 22:23
  • @hpekristiansen Yes, but this does not work for too small radii. The node will retain a width greater than the minimum width. – user121799 Aug 13 '18 at 22:24
6

at node with circle shape is radius equal to minimum size/2, of course if you set inner sep to zero. node features can define local at node or as new style with tikzpicture options or globally with tikzset in preamble of a document. for example:

\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 6pt  % size of the circle diameter 
                    ]  
\node[dot,label=below left:radius 3pt] at (0,0) {};
\node[dot=5pt,label=below left:radius 5pt] at (3,0) {};
\draw[red, semitransparent] (0,0) circle[radius=3pt];% test of the radius size
\end{tikzpicture}
\end{document}

or

\documentclass[tikz, margin=3mm]{standalone}
\tikzset{
dot/.style = {circle, fill, minimum size=#1,
              inner sep=0pt, outer sep=0pt},
dot/.default = 6pt % size of the circle diameter 
}
\begin{document}
\begin{tikzpicture}                   ]  
\node[dot,label=below left:radius 3pt] at (0,0) {};
\node[dot=10pt,label=below left:radius 5pt] at (3,0) {};
\draw[red, semitransparent] (0,0) circle[radius=3pt];% test of the radius size
\end{tikzpicture}
\end{document}

enter image description here

6

Interesting, here a test of the commands, according to what I found that the dimension of the shapes in text nodes, in this case circle, depends on the text_node_content_shape_dimmension + the_internal_separation (inner sep); as it defines itself the minimum size, it would only define the size if the dimension of the text + the internal separation are less than the minimum size; In this way, if we want to ensure that the dimension of the shape is determined by the minimum size, the value of the internal separation must subtract from the value corresponding to the text so that both summations are lower than the minimun size.

RESULT: Multiple option-results to see how the controls works for shape size even if it contains text.

enter image description here

MWE:

\usepackage{tikz}
\usetikzlibrary{arrows.meta}

\begin{document}
    \begin{tikzpicture}[
        >={Stealth[inset=0pt,length=2pt]},
        line width=0.1pt,
        fill opacity=0.2,
        text opacity=1,
    ]
    %Grid in pt units
    \draw[black!30,step=1pt] (0,0) grid (30pt,-120pt);
    \draw[black!80,step=10pt,line width=0.2pt] (0,0) grid (30pt,-120pt);
    \draw[|-|,line width=0.2pt] (0,0)++(0,3pt)-- ++(10pt,0) node[midway](n){};
    \draw[<-] (n.center) |- ++(10pt,5pt) node [anchor=180, inner sep=0pt]{\tiny \verb+10pt+};

    %Drawing a shape
    \draw[fill]
    (15pt,-5pt)
        circle (3pt)
        ++ (15pt,0)
        node[anchor=180, font=\tiny]{\verb+\draw[fill](x,y) circle (3pt);+};
    %Drawing a node
    \draw[blue]
    (15pt,-15pt)
        node [fill,draw,circle,label=below left:$x$]{}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$x$]at(x,y){};+};

    \draw[blue!50!cyan]
    (15pt,-25pt)
        node [fill,draw,circle,label=below left:$x$] {$x$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$x$]at(x,y){$x$};+};

    \draw[green!50!blue]
    (15pt,-35pt)
        node [fill,draw,circle,label=below left:$x$, inner sep=0pt] {$x$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$x$,inner sep=0pt]at(x,y){$x$};+};

    \draw[green!50!black]
    (15pt,-45pt)
        node [fill,draw,circle,label=below left:$h$, inner sep=0pt] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,inner sep=0pt]at(x,y){$h$};+};

    \draw[green!50!orange]
    (15pt,-55pt)
        node [fill,draw,circle,label=below left:$h$,inner sep=-1pt] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,inner sep=-1pt]at(x,y){$h$};+};

    \draw[orange]
    (15pt,-65pt)
        node [fill,draw,circle,label=below left:$h$,minimum size=6pt] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,minimum size=6pt]at(x,y){$h$};+};

    \draw[red]
    (15pt,-75pt)
        node [fill,draw,circle,label=below left:$h$,minimum size=6pt, inner sep=0pt] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,minimum size=6pt,inner sep=0pt]at(x,y){$h$};+};

    \draw[red!50!black]
    (15pt,-85pt)
        node [fill,draw,circle,label=below left:$h$, inner sep=-2] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,inner sep=-2]at(x,y){$h$};+};

    \draw[blue!50!black]
    (15pt,-95pt)
        node [fill,draw,circle,label=below left:$h$,minimum size=6, inner sep=-2] {$h$}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,minimum size=6,inner sep=-2]at(x,y){$h$};+};

    \draw[blue!50!purple]
    (15pt,-105pt)
        node [fill,draw,circle,label=below left:$h$,minimum size=6, inner sep=-2] {}
        ++(15pt,0)
        node[anchor=180, font=\tiny]{\verb+\node[fill,draw,circle,label=below left:$h$,minimum size=6,inner sep=-2]at(x,y){};+};

    \draw[densely dashed]
    (12pt,0) -- ++(0,-125pt)
    (18pt,0) -- ++(0,-125pt);
    \draw[|-|,line width=0.2pt] (0,-120pt)++(12pt,-4pt)-- ++(6pt,0) node[midway](n){};
    \draw[<-] (n.center) |- ++(10pt,-5pt) node [anchor=180, inner sep=0pt]{\tiny \verb+6pt+};

    \end{tikzpicture}

\end{document}

PSD:

  • Result scale is 3.5;
  • In the code I use: \draw[draw_style_opt](coordinate) node[node_style_opt]{node_text_content}; instead \node[node_style_opt] at (coordinate) {node_text_content}; because draw_style_opt affects all styles within command line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.