我知道 Ti钾Z,我们可以在使用命令时指定圆的半径\draw
,例如:
\draw[fill] (1,2) circle (3pt);
但是当您通过命令绘制圆时,如何指示半径\node
,如下所示?
\node[fill,circle,label=below left:$x$] at (1,2) {};
例如,假设我想要一个半径为 3pt 的圆:
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\node[fill,circle,label=below left:$x$] at (1,2) {};
\end{tikzpicture}
\end{document}
我更喜欢看到两种方法来实现这一点:一种方法仅适用于特定的(填充的)圆圈,第二种方法可以全局用于整个图片。
答案1
一个具有圆形形状的节点,其圆的半径等于minimum size/2
,当然,如果您将其设置inner sep
为零。节点特征可以在节点处局部定义,或tikzpicture
使用选项将其定义为新样式,或者tikzset
在文档的序言中全局定义。例如:
\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}
或者
\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}
答案2
有趣的是,这里是对命令的测试,根据我的发现,文本节点中形状的尺寸(在本例中为圆形)取决于 + text_node_content_shape_dimmension
;the_internal_separation (inner sep)
因为它将自己定义为minimum size
,所以只有当文本的尺寸 + 内部分隔小于 时,它才会定义大小minimum size
;这样,如果我们想确保形状的尺寸由 决定the minimum size
,则必须从对应于文本的值中减去内部分隔的值,以使两个总和都低于minimun size
。
结果:多个选项结果可查看控件如何控制形状大小,即使它包含文本。
梅威瑟:
\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}
附录:
- 结果比例为 3.5;
- 在代码中我使用:
\draw[draw_style_opt](coordinate) node[node_style_opt]{node_text_content}
;而不是\node[node_style_opt] at (coordinate) {node_text_content}
;因为draw_style_opt
会影响命令行内的所有样式。