答案1
那样的东西适合你吗?
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary[decorations.markings]
\begin{document}
\begin{tikzpicture}[arr/.style={
postaction={decorate},
decoration={
markings,
mark=at position #1 with {\arrow{>}}}}]
\draw[arr=0.6] (0,0) -- (0,1) node[pos=0.6,right]{A};
\draw (0,1) to[out=90,in=90,looseness=2] (1,1);
\draw[arr=0.5] (1,1) -- (1,0)node[pos=0.4,right]{A};
\draw (1,0) to[out=-90,in=-90,looseness=2] (2,0);
\draw[arr=0.6] (2,0) -- (2,1)node[pos=0.6,right]{A};
\end{tikzpicture}
\end{document}
答案2
你也可以使用arc
s。对于一般形状,类似
\draw (0,0) -- (0,1) arc[start angle=180, delta angle=-180, radius=0.5]
-- (1,0) arc[start angle=180, delta angle=180, radius=0.5]
-- (2,1);
由于垂直线相距 1,因此圆弧的半径为 0.5。 定义start angle
了 所属圆的“锚点” arc
。对于这两种情况,arc
应该从圆的最左点开始,start angle=180
。由于第一条圆弧从 180 度逆时针旋转到零度,因此我设置delta angle=-180
。第二条圆弧顺时针旋转,因此delta angle=180
。
各种例子,其中我采用了arr
标记的风格 SebGlav 的回答,因此,这值得称赞。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
arr/.style={
postaction={decorate},
decoration={
markings,
mark=at position #1 with {\arrow{>}}}}
}
\begin{document}
% just simple shape
\begin{tikzpicture}
\draw (0,0) -- (0,1) arc[start angle=180, delta angle=-180, radius=0.5]
-- (1,0) arc[start angle=180, delta angle=180, radius=0.5]
-- (2,1);
\end{tikzpicture}
% same shape with arrows
% arrow positions found by trial and error
\begin{tikzpicture}[
arr/.style={
postaction={decorate},
decoration={
markings,
mark=at position 0.1 with {\arrow{>}},
mark=at position 0.5 with {\arrow{>}},
mark=at position 0.925 with {\arrow{>}}
}
}
]
\draw [arr] (0,0) -- (0,1) arc[start angle=180, delta angle=-180, radius=0.5]
-- (1,0) arc[start angle=180, delta angle=180, radius=0.5]
-- (2,1);
\end{tikzpicture}
% separate paths
\begin{tikzpicture}
% first the three straight lines
% saving some coordinates for use later
\draw [arr=0.5] (0,0) -- node[left] {$A$} (0,1) coordinate (m1);
\draw [arr=0.5] (1,1) -- node[left] {$A$} (1,0) coordinate (m2);
\draw [arr=0.5] (2,0) -- node[left] {$A$} (2,1);
% then the two arcs
\draw (m1) arc[start angle=180, delta angle=-180, radius=0.5]
(m2) arc[start angle=180, delta angle=180, radius=0.5];
\end{tikzpicture}
% single draw, but with edge (which actually makes separate paths)
% because of edge, coordinates have to be repeated
\begin{tikzpicture}
\draw (0,0) edge[arr=0.5] node[left] {$A$} (0,1)
(0,1) arc[start angle=180, delta angle=-180, radius=0.5]
edge[arr=0.5] node[left] {$A$} (1,0)
(1,0) arc[start angle=180, delta angle=180, radius=0.5]
edge[arr=0.5] node[left] {$A$} (2,1);
\end{tikzpicture}
\end{document}