我正在使用以下代码在图表上创建箭头:
\tikzset{
set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
set arrow inside={end/.initial=>, opt/.initial=},
/pgf/decoration/Mark/.style={
mark/.expanded=at position #1 with
{
\noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
}
},
arrow inside/.style 2 args={
set arrow inside={#1},
postaction={
decorate,decoration={
markings,Mark/.list={#2}
}
}
},
}
可以了。但是,它生成的是逆时针箭头,而我需要的是顺时针箭头。
完整代码如下:
\begin{figure}[b]
\centering
\begin{tikzpicture}
\draw[thick,<->](0,10) node[above]{$u$}--(0,0)--(10,0) node[right]{$K$};
\node[below left] at (0,0);
\node[below] at (5,0){$K^*$};
\node[left] at (0,5){$u^*$};
\draw(0,5)--(9,5) node[right]{$\hat{K}=0$};
\draw(5,0)--(5,9) node[above]{$\hat{u}=0$};
\draw[-stealth] (3,2) -- (3,4);
\draw[-stealth] (3,2) -- (1,2);
\draw[-stealth] (7,8) -- (9,8);
\draw[-stealth] (7,8) -- (7,6);
\draw[-stealth] (1,6) -- (1,8);
\draw[-stealth] (1,6) -- (3,6);
\draw[-stealth] (9,4) -- (9,2);
\draw[-stealth] (9,4) -- (7,4);
\draw[blue](5,5) circle [radius=2]
[arrow inside={end=stealth,opt={red,scale=2}}{0.25,0.75}];
\end{tikzpicture}
\caption{}%
\figlabel{}
\end{figure}
谢谢。
答案1
您可以通过将比例设置为负值来反转 Tikz 中很多事物的方向,这里的比例为 2,我将其更改为 -2,从而得到上图的结果。
\documentclass[tikz, border=20]{standalone}
\usetikzlibrary{decorations.markings}
\tikzset{
set arrow inside/.code={\pgfqkeys{/tikz/arrow inside}{#1}},
set arrow inside={end/.initial=>, opt/.initial=},
/pgf/decoration/Mark/.style={
mark/.expanded=at position #1 with
{
\noexpand\arrow[\pgfkeysvalueof{/tikz/arrow inside/opt}]{\pgfkeysvalueof{/tikz/arrow inside/end}}
}
},
arrow inside/.style 2 args={
set arrow inside={#1},
postaction={
decorate,decoration={
markings,Mark/.list={#2}
}
}
},
}
\begin{document}
\begin{tikzpicture}
\draw[thick,<->](0,10) node[above]{$u$}--(0,0)--(10,0) node[right]{$K$};
\node[below left] at (0,0){};
\node[below] at (5,0){$K^*$};
\node[left] at (0,5){$u^*$};
\draw(0,5)--(9,5) node[right]{$\hat{K}=0$};
\draw(5,0)--(5,9) node[above]{$\hat{u}=0$};
\draw[-stealth] (3,2) -- (3,4);
\draw[-stealth] (3,2) -- (1,2);
\draw[-stealth] (7,8) -- (9,8);
\draw[-stealth] (7,8) -- (7,6);
\draw[-stealth] (1,6) -- (1,8);
\draw[-stealth] (1,6) -- (3,6);
\draw[-stealth] (9,4) -- (9,2);
\draw[-stealth] (9,4) -- (7,4);
\draw[blue](5,5) circle [radius=2]
[arrow inside={end=stealth,opt={red,scale=-2}}{0.25,0.75}]; % was scale=2 before
\end{tikzpicture}
\end{document}