
私はここでポール・ガボリットのソリューションを使用して、tikzでパスを描画しようとしていますTikZ: 線の真ん中に矢印を描くにはどうすればいいですか?パスが環状部の半分になるこの状態を実現できました。
しかし、左下の矢印と内側の半円の矢印は右に行くようにしたいです(そうすれば、パスを横断するときにすべての矢印が同じ方向になり、環状部の内側が左になります)。
ペイントでの私の下手な編集
私が使用しているコードは
\usepackage{tikz}
\usetikzlibrary{positioning, calc, arrows, decorations.markings, decorations.pathreplacing}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\begin{center}
\begin{tikzpicture}[domain=0:4]
\draw [<->, very thick] (0,4) node (yaxis) [above] {$y$}
|- (-4,0) node (zaxis) [left] {}
|- (4,0) node (xaxis) [right] {$x$}
;
\path [draw=black, ultra thick, postaction={on each segment={mid arrow=black}}] (3,0) arc (0:180:3cm)
(1,0) -> (3,0)
(1,0) arc (0:180:1cm)
(-1,0) -> (-3,0) ;
\end{tikzpicture}
\end{center}
ご協力いただければ幸いです:)
答え1
今後は、完全な投稿を検討してください最小限の動作例 (MWE)他の人があなたを支援しやすくなります。:-)
Paul Gaborit のコードでは、パスが通過する方向に矢印が適用されます。したがって、この場合、問題のあるパス セグメントの方向を変更するだけで済みます。
環境内で変更する必要があったのは 2 行のコードだけでtikzpicture
、これらの変更は両方とも、以下のコード内のコメント行に詳しく記載されています。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc, arrows, decorations.markings, decorations.pathreplacing}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\draw [<->, very thick] (0,4) node (yaxis) [above] {$y$}
|- (-4,0) node (zaxis) [left] {}
|- (4,0) node (xaxis) [right] {$x$}
;
\path [draw=black, ultra thick, postaction={on each segment={mid arrow=black}}] (3,0) arc (0:180:3cm)
(1,0) -> (3,0)
(-1,0) arc (180:0:1cm) % changed starting point and swapped arc bounding angles
(-3,0) -> (-1,0) ; % swapped coordinates here
\end{tikzpicture}
\end{document}