
如果我做
\draw (1,1) circle (1pt)
1pt
tikz 畫一個直徑為 的小圓(1,1)
。
我怎麼能定義一條cross
路徑
\draw (1,1) cross (1pt)
畫一個有直徑的小十字1pt
(可以像圓圈一樣調整大小)?
答案1
cross
相當於的命令circle
不存在,TiKZ
但您可以使用庫cross out
中的節點。shapes.misc
這種節點添加了交叉節點的文本,但很容易對其進行調整以執行您想要的操作。
\tikzset{cross/.style={cross out, draw,
minimum size=2*(#1-\pgflinewidth),
inner sep=0pt, outer sep=0pt}}
因為circle (1pt)
繪製一個半徑為 1pt 的圓,所以它的總大小將為 2pt,然後節點的大小由和cross
定義,並且間距固定為。minimum size=2*(#1-\pgflinewidth)
inner
outer
0pt
如果交叉角度不是您想要的,您可以透過rotate
選項來變更它。接下來你有一些例子。我還把circles
它們放在上面只是為了表明圓圈和十字具有相同的大小。
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.misc}
\tikzset{cross/.style={cross out, draw=black, minimum size=2*(#1-\pgflinewidth), inner sep=0pt, outer sep=0pt},
%default radius will be 1pt.
cross/.default={1pt}}
\begin{document}
\begin{tikzpicture}[]
\draw (0,0) circle (1pt);
\draw (.5,0) node[cross,rotate=10] {};
\draw (.5,0) circle (1pt);
\draw (0,.5) circle (1pt);
\draw (0,.5) node[cross,red] {};
\draw (.5,.5) node[cross,rotate=30] {};
\draw (0.25,.25) circle (2pt);
\draw (0.25,.25) node[cross=2pt,rotate=45,green]{};
\end{tikzpicture}
\end{document}
答案2
Alternative solution using pic
:
\documentclass[]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\tikzset{
cross/.pic = {
\draw[rotate = 45] (-#1,0) -- (#1,0);
\draw[rotate = 45] (0,-#1) -- (0, #1);
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,0) circle (1pt);
\path (.5,0) pic[rotate = 10] {cross=1pt};
\draw (.5,0) circle (1pt);
\draw (0,.5) circle (1pt);
\path (0,.5) pic[red] {cross=1pt};
\draw (.5,.5) pic[rotate = 30] {cross=1pt};
\draw (0.25,.25) circle (2pt);
\draw (0.25,.25) pic[rotate=45,green] {cross=2pt};
\end{tikzpicture}
\end{document}
答案3
您可以在對應位置寫一個“x”:
\draw (1,1) node {x};
然後,您可以使用字體大小調整大小,如下所示:
\draw (1,1) node {\Huge x};
「x」的中心實際上正好位於給定的座標處。