我在尝试让 tikz 根据箭头底部而不是中心来定位箭头时遇到了麻烦。似乎中心是默认的。我该如何覆盖该默认设置?
以下是 MWE:\
documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary[shapes.arrows]
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=1.7, every node/.style={single arrow, draw=none}]
\begin{axis}[ xmin=-1.0,xmax=1.0,
ymin=-0.2,ymax=6.7,
]
\plot[name path=A, thick,samples=100,domain=-1:1] {4- sin(180*x)};
\plot[name path=B,thick,samples=100,domain=-1:1] {1+x^2};
\addplot[fill=gray,opacity=0.4] fill between [of=A and B];
\draw[dotted] (-1,0)--(-1,2);
\draw[dotted] (1,0)--(1,2);
\node [fill=green, single arrow head indent=1ex,minimum height=5cm,
minimum width=2cm,rotate=90] at (-0.5,1.25) {};
\node[] at (-0.5,1.25) {Start Here!};
\end{axis}
\end{tikzpicture}
\caption{I need the arrwo to start in the bottom curve}
\label{subfig1}
\end{figure}
\end{document}
答案1
添加anchor=west
到节点选项。您需要的是west
锚点,而不是south
,因为节点是旋转的,并且节点的锚点也会随之旋转。
如果你的目的是在两个函数之间画一个粗箭头,那么最好使用类似
\draw [line width=5mm,
-{Stealth[width=15mm, length=10mm, inset=1mm]},
blue]
(-0.5, {G(-0.5)}) -- (-0.5, {F(-0.5)});
我认为,其中F
和G
是用定义的函数declare function
。(不过您不必这样做,您可以直接在坐标中编写函数表达式,用替换x
。-0.5
)Stealth
箭头来自arrows.meta
库,因此必须加载。
\documentclass{article}
\usepackage{pgfplots} % loads tikz, you don't have to do it explicitly
\usetikzlibrary{shapes.arrows, arrows.meta}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[
every node/.style={single arrow, draw=none},
declare function={
F(\x) = 4- sin(180*\x);
G(\x) = 1+\x*\x;
}
]
\begin{axis}[
xmin=-1.0,xmax=1.0,
ymin=-0.2,ymax=6.7,
width=10cm,
samples=100,
domain=-1:1
]
\addplot[name path=A, thick] {F(x)};
\addplot[name path=B,thick] {G(x)};
\addplot[fill=gray,opacity=0.4] fill between [of=A and B];
\draw[dotted] (-1,0)--(-1,2);
\draw[dotted] (1,0)--(1,2);
\node [fill=green, single arrow head indent=1ex,minimum height=5cm,
minimum width=2cm,rotate=90, anchor=west] at (-0.5,1.25) {};
\draw [line width=5mm,
-{Stealth[width=15mm, length=10mm, inset=1mm]},
blue]
(-0.5, {G(-0.5)}) -- (-0.5, {F(-0.5)});
\end{axis}
\end{tikzpicture}
\caption{I need the arrwo to start in the bottom curve}
\label{subfig1}
\end{figure}
\end{document}