![调整箭头的位置](https://linux22.com/image/479812/%E8%B0%83%E6%95%B4%E7%AE%AD%E5%A4%B4%E7%9A%84%E4%BD%8D%E7%BD%AE.png)
可以看出,箭头的定位不正确。我可以通过指示 7.95 而不是 8 来改进。有没有更可靠的方法?
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{arrows,decorations.markings}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
[extended line/.style={shorten >=-#1,shorten <=-#1},
/pgf/declare function={f(\x)=6*\x;},
/pgf/declare function={g(\x)=4*\x + 16;}]
\begin{axis}[
restrict x to domain=-1:14, xmax=14, xmin=-1,
restrict y to domain=-10:100, ymax=100, ymin=-10,
x=1cm,
y=0.1cm,
axis x line=middle,
axis y line=middle,
major tick style=black,
axis line style = very thick,
tick align=outside,
tickwidth=0.12cm,
tick style=thick,
grid=both,
xtick={0,1,...,13},
ytick={0,10,...,90},
extra x ticks={-1,14},
extra x tick label={\null},
extra y ticks={-10,100},
extra y tick label={\null},
extra tick style={tick style={draw=none}},
xlabel=$x$,ylabel=$y$,
every axis x label/.style={
at={(ticklabel* cs:1.01)},anchor=west},
every axis y label/.style={
at={(ticklabel* cs:1.01)}, anchor=south},
x tick label style={
/pgf/number format/1000 sep={},
},
y tick label style={
/pgf/number format/1000 sep={},
},
samples=2000,
axis on top=false,
>=stealth]
\addplot [very thick,domain=0:14] {f(x)};
\addplot [very thick,domain=0:14] {g(x)};
\addplot [very thick,domain=8:14,red] {f(x)};
\draw[red,dashed,thick](8,0) -- (8,{f(8)}) -- (0,{f(8)});
\draw[arrows={Bracket[reversed,line join=miter]->},red,very thick]
(8,0) -- (14,0);
\node[below left=2pt] at (0,0) {0};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[>=stealth]
\draw[help lines] grid (4,2);
\draw[arrows={Bracket[reversed,line join=miter]->},red,very thick] (1,2) -- (3,2); % initial example
\draw[postaction={decorate},red,very thick, decoration={
markings,% switch on markings
mark=at position -0.001cm with {\arrow[red,very thick]{>}},
mark=at position 0pt with {\arrow[red,very thick]{Bracket[]}}
}] (1,1) -- (3,1); % all purpose solution
\draw[postaction={decorate},red,very thick,decoration={
markings,% switch on markings
mark=at position -0.001cm with {\arrow[red,very thick]{>}},
mark=at position 1.1pt with {\arrow[red,very thick]{Bracket[]}}
},shorten >=1.2pt] (1,0) -- (3,0); % better looking but not self-adapting to different marking sizes
\end{tikzpicture}
\end{document}
两种解决方案,均不完美:
在第二行,括号现在有点太靠左了,不符合我的口味,并且段的方角现在稍微突出了尖端。
第三行,看起来不错,但如果你改变装饰的尺寸,它不会自适应