![在曲线上画箭头(转换图)](https://linux22.com/image/380635/%E5%9C%A8%E6%9B%B2%E7%BA%BF%E4%B8%8A%E7%94%BB%E7%AE%AD%E5%A4%B4%EF%BC%88%E8%BD%AC%E6%8D%A2%E5%9B%BE%EF%BC%89.png)
我正在尝试复制下面的转换图:
到目前为止,我已经成功绘制所有线条并使用以下代码标记我的节点:
\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{flexisym}
\usepackage{wallpaper}
\usepackage{blkarray}
\usepackage{caption}
\usepackage{booktabs, makecell, multirow}
\usepackage{stackengine,graphicx,xcolor}
\usepackage{lscape}
\usetikzlibrary{arrows}
\usepackage{flexisym}
\usetikzlibrary{shapes.geometric}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[a/.style = {insert new path = {-triangle 90}}]
%\draw[thick] (0,0) --+ (1,3) --+ (5,3) --+ (4,0) --+ (0,0);
%\draw[thick] (0,0) --+ (1,1.73) --+ (3,1.73) --+ (4,0)--+ (3,-1.73)--+ (1,-1.73)--+ (0,0);
%
\draw[thick,fill=black] (0,0) circle (1.5mm);
\draw[thick,fill=black] (5,0) circle (1.5mm);
\draw[thick,fill=black] (2.5,-3.5) circle (1.5mm);
%
\node [left] at (-0.15, 0.2) {$C$};
\node [right] at (5.2,0.2) {$S$};
\node [below] at (2.5,-3.7) {$T$};
%\node [right] at (4, 0) {$X$};
%\node [below] at (3, -1.73) {$Y$};
%\node [below] at (1, -1.73) {$Z$};
%
\draw[thick](-0.6,0.5) circle (0.8cm);
\draw[thick](0,0) to [bend right=20](5,0);
\draw[thick](0,0) to [bend left=20](5,0);
%
\draw[thick](5.6,0.5) circle (0.8cm);
\draw[thick](0,0) to [bend right=20](2.5,-3.5);
\draw[thick](0,0) to [bend left=20](2.5,-3.5);
%
\draw[thick](2.5,-4.27) circle (0.8cm);
\draw[thick](5,0) to [bend right=20](2.5,-3.5);
\draw[thick](5,0) to [bend left=20](2.5,-3.5);
%
%\draw[thick,opacity=0.7,fill=black] (2.5,1.5) circle (0.5mm);
%\node[above] at (2.5,1.65) {$M$};
\end{scope}
\end{tikzpicture}
\end{document}
我得到以下输出:
有经验的人能告诉我如何在曲线上插入这些箭头吗?
谢谢。
答案1
可以使用 decorations.markings 实现曲线中更好的箭头方向,它允许您沿路径插入任何图形;然后我使用命令提供的所有选项简化了您的代码。
梅威瑟:
\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
%Environment config
%Environment Styles
Circ/.style={circle, fill, minimum width=12pt},
MidArrow/.style={
draw,thick, postaction={decorate,decoration={markings,mark=at position 0.5 with {\fill(0:5pt) -- (120:5pt) -- (240:5pt);}}}}
]
%Drawing the nodes
%\node[tikzstyle, label=angle_orientation:Text](Node_coordinate_Identifier) at (position_in_polar_coordinates){Text_none};
\node[Circ, label=30:$S$](S) at (30:2.5){};
\node[Circ, label=150:$P$](P) at (150:2.5){};
\node[Circ, label=270:$T$](T) at (270:2.5){};
%Drawing the arrows
\draw[MidArrow] (P) to [bend left=20] node[anchor=-90, inner sep=8pt]{40\%} (S);
\draw[MidArrow] (S) to [bend left=20] node[anchor=-90, inner sep=6pt]{20\%} (P);
\draw[MidArrow] (P) to [bend left=20] node[anchor=50, inner sep=4pt]{20\%} (T);
\draw[MidArrow] (T) to [bend left=20] node[anchor=30, inner sep=4pt]{20\%} (P);
\draw[MidArrow] (T) to [bend left=20] node[anchor=-60, inner sep=8pt]{20\%} (S);
\draw[MidArrow] (S) to [bend left=20] node[anchor=180, inner sep=6pt]{20\%} (T);
\draw[MidArrow] (P) arc (150-180:150-180-360:0.8) node [midway, anchor=150-180,inner sep=4pt]{40\%};
\draw[MidArrow] (S) arc (30-180:30-180-360:0.8) node [midway, anchor=30-180,inner sep=4pt]{60\%};
\draw[MidArrow] (T) arc (270-180:270-180-360:0.8)node [midway, anchor=270-180,inner sep=6pt]{60\%};
\end{tikzpicture}
\end{document}
更新:
增加了控制曲线中箭头位置的可能性;然后使用相当于的选项来控制标签位置pos={0_to_1_value}
,midway
并pos=0.5
使用 \sf 获取百分比符号的衬线字体来重现更类似于示例的结果,展示了基本 tikz 命令提供的极大灵活性。
结果:
梅威瑟:
\documentclass[border=10pt,tikz]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
%Environment config
%Environment Styles
Circ/.style={circle, fill, minimum width=12pt},
InLineArrow/.style={
draw,thick, postaction={decorate,decoration={markings,mark=at position #1 with {\fill(0:5pt) -- (120:5pt) -- (240:5pt);}}}}
]
%Drawing the nodes
%\node[tikzstyle, label=angle_orientation:Text](Node_coordinate_Identifier) at (position_in_polar_coordinates){Text_none};
\node[Circ, label=30:$S$](S) at (30:2.5){};
\node[Circ, label=150:$P$](P) at (150:2.5){};
\node[Circ, label=270:$T$](T) at (270:2.5){};
%Drawing the arrows
\draw[InLineArrow=0.5] (P) to [bend left=20] node[anchor=-90, inner sep=8pt]{40\sf\%} (S);
\draw[InLineArrow=0.5] (S) to [bend left=20] node[anchor=-90, inner sep=6pt]{20\sf\%} (P);
\draw[InLineArrow=0.5] (P) to [bend left=20] node[anchor=50, inner sep=4pt]{20\sf\%} (T);
\draw[InLineArrow=0.5] (T) to [bend left=20] node[anchor=30, inner sep=4pt]{20\sf\%} (P);
\draw[InLineArrow=0.5] (T) to [bend left=20] node[anchor=-60, inner sep=8pt]{20\sf\%} (S);
\draw[InLineArrow=0.5] (S) to [bend left=20] node[anchor=180, inner sep=6pt]{20\sf\%} (T);
\draw[InLineArrow=0.41] (P) arc (150-180:150-180-360:0.8) node [pos=0.41, anchor=180-180,inner sep=7pt]{40\sf\%};
\draw[InLineArrow=0.58] (S) arc (30-180:30-180-360:0.8) node [pos=0.58, anchor=0-180,inner sep=7pt]{60\sf\%};
\draw[InLineArrow=0.75] (T) arc (270-180:270-180-360:0.8)node [pos=0.65, anchor=180-180,inner sep=7pt]{60\sf\%};
\end{tikzpicture}
\end{document}
答案2
绝对不是最好的答案,但它有效:
\documentclass[border=5pt,tikz]{standalone}
\usetikzlibrary{arrows,decorations.markings}
%%% https://tex.stackexchange.com/questions/39278/tikz-arrowheads-in-the-center
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
%%%
\begin{document}
\begin{tikzpicture}[>=triangle 60]
\begin{scope}[a/.style = {insert new path = {-triangle 90}}]
\draw[thick,fill=black] (0,0) circle (1.5mm);
\draw[thick,fill=black] (5,0) circle (1.5mm);
\draw[thick,fill=black] (2.5,-3.5) circle (1.5mm);
\node [left] at (-0.15, 0.2) {$C$};
\node [right] at (5.2,0.2) {$S$};
\node [below] at (2.5,-3.7) {$T$};
\draw[->-=.5,thick](.2,0.5) arc(0:-360:.8cm);
\draw[->-=.5,thick](5,0) to [bend left=20](0,0);
\draw[->-=.5,thick](0,0) to [bend left=20](5,0);
\draw[xshift=11.25cm,xscale=-1,->-=.5,thick](5.6,0.5) circle (0.8cm);
\draw[->-=.5,thick](2.5,-3.5) to [bend left=20](0,0);
\draw[->-=.5,thick](0,0) to [bend left=20](2.5,-3.5);
\draw[yscale=-1,yshift=8.55cm,->-=.5,thick](2.5,-4.27) circle (0.8cm);
\draw[->-=.5,thick](2.5,-3.5) to [bend left=20](5,0);
\draw[->-=.5,thick](5,0) to [bend left=20](2.5,-3.5);
\end{scope}
\end{tikzpicture}
\end{document}
输出如下:
编辑:只需替换一些[… ->-=.5 …]
即可[… ->-=.55 …]
将箭头放在“准确位置”(整个箭头与下面的箭头合并)。
答案3
可以在 Ti 中定义箭头样式钾z. 我使用了这个答案。
放入\usetikzlibrary{decorations.markings}
序言,然后在下面写下以下代码\begin{document}
\tikzset{middlearrow/.style={
decoration={markings,
mark= at position 0.5 with {\arrow{#1}} ,
},
postaction={decorate}
}
}
然后,写入参数middlearrow={'type of arrow here'}
。我使用了stealth reversed
。
答案4
imgur 恢复后,我可以看到所需的输出。我想说的是箭头变得稍微好看一点
- 当箭弯了
- 一种是使用更加对称的符号坐标
- 并允许任意位置。
否则,这篇文章与其他精彩答案有很大的重叠。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings,arrows.meta,bending}
\begin{document}
% inspired by https://tex.stackexchange.com/a/316050/121799
% and further developed in https://tex.stackexchange.com/a/430239/121799
\tikzset{
arc arrow/.style args={%
to pos #1 and length #2 and label #3}{
decoration={
markings,
mark=at position 0 with {\pgfextra{%
\pgfmathsetmacro{\tmpArrowTime}{#2/(\pgfdecoratedpathlength)}
\xdef\tmpArrowTime{\tmpArrowTime}}},
mark=at position {#1-\tmpArrowTime} with {\coordinate(@1);},
mark=at position {#1-2*\tmpArrowTime/3} with {\coordinate(@2);},
mark=at position {#1-\tmpArrowTime/3} with {\coordinate(@3);},
mark=at position {#1} with {\coordinate(@4);
\draw[-{Triangle[bend,length=#2]}]
(@1) .. controls (@2) and (@3) .. (@4)
node[pos=0.8,auto,font=\sffamily]{#3};},
},
postaction=decorate,
}
}
\begin{tikzpicture}
\begin{scope}[thick]
%
\draw[fill=black] (150:3.5) coordinate[label={[above left=2pt]P}] (P) circle (1.5mm);
\draw[fill=black] (30:3.5) coordinate[label={[above right=2pt]S}] (S) circle (1.5mm);
\draw[fill=black] (-90:3.5) coordinate[label={[below=2pt]T}] (T) circle (1.5mm);
%
\draw[arc arrow=to pos 0.45 and length 3mm and label {40\,\%}](P) arc(-30:-390:0.8cm);
\draw[arc arrow=to pos 0.5 and length 3mm and label {20\,\%}](P) to [bend left=20] (T);
\draw[arc arrow=to pos 0.5 and length 3mm and label {20\,\%}](T) to [bend left=20] (P);
%
\draw[arc arrow=to pos 0.65 and length 3mm and label {60\,\%}](S) arc(210:-150:0.8cm);
\draw[arc arrow=to pos 0.5 and length 3mm and label {20\,\%}](S) to [bend left=20] (P);
\draw[arc arrow=to pos 0.5 and length 3mm and label {40\,\%}](P) to [bend left=20] (S);
%
\draw[arc arrow=to pos 0.7 and length 3mm and label {60\,\%}](T) arc(90:-270:0.8cm);
\draw[arc arrow=to pos 0.5 and length 3mm and label {20\,\%}](T) to [bend left=20] (S);
\draw[arc arrow=to pos 0.5 and length 3mm and label {20\,\%}](S) to [bend left=20] (T);
%
\end{scope}
\end{tikzpicture}
\end{document}