当我尝试使用以下代码绘制角度 alpha 和 theta 时,我在角度上得到了一些奇怪的间隙或悬垂。这是我第一次使用 tikz 绘制角度,所以我不知道我是否做错了什么。谢谢您的帮助!
\begin{figure}
\centering
\begin{tikzpicture}
\coordinate (test2) at (0,0);
\draw[->, thick] (0,0) -- (4,0) node[right] (test1) {x};
\draw[->, thick] (0,0) -- (0,4) node[above] {y};
\draw[->] (0, 0) -- (2, 2) node[below] (test3) {r};
\draw pic[pic text = {$\theta$}, draw, -, angle eccentricity=1.3, angle radius = 15] {angle = test1--test2--test3};
\draw[dashed] (2, 2) -- (2, {2 + 1.25}) node[] (dashed) {};
\draw (2, 2) -- ({2+1}, {2 + 0.5}) node[] (bold) {};
\draw pic[pic text = {$\alpha$}, draw, -, angle eccentricity=1.2, angle radius = 30] {angle = bold--test3--dashed};
\draw[dashed] ({sqrt(8)}, 0) arc[start angle = 0, end angle = 90, radius ={sqrt(8)}];
\end{tikzpicture}
\caption{Caption}
\label{fig:halbachwinkel}
\end{figure}
答案1
角度处的间隙是由于使用节点名称作为定义角度的坐标造成的。如果您将这些节点替换为\coordinate
,则一切都会正常工作:
\documentclass[12pt, margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{angles, arrows.meta, % new
quotes} % new
\begin{document}
\begin{tikzpicture}[
ang/.style = {draw, Straight Barb-Straight Barb, anchor=west,
angle radius = 8mm, angle eccentricity=1},
arr/.style = {cap=round,-Straight Barb},
]
\coordinate (test2) at (0,0);
% axix
\draw[arr] (0,0) -- (4,0) node[right] (test1) {x};
\draw[arr] (0,0) -- (0,4) node[above] {y};
% vector
\draw[arr, thick] (test2) -- (2, 2)
coordinate[label={[inner sep=1ex]270:r}] (test3);
% angle theta
\pic[ang, "$\theta$"] {angle = test1--test2--test3};
% circle
\draw[densely dashed] ({sqrt(8)},0) arc (0:90:{sqrt(8)});
% angle alpha
\draw[dashed] (test3) -- ++ (0,1.25) coordinate (dashed) {};
\draw (test3) -- ++ (+1,0.5) coordinate (bold) {};
\pic[ang, "$\alpha$"] {angle = bold--test3--dashed};
\end{tikzpicture}
\end{document}