![括号放置的精确度](https://linux22.com/image/419949/%E6%8B%AC%E5%8F%B7%E6%94%BE%E7%BD%AE%E7%9A%84%E7%B2%BE%E7%A1%AE%E5%BA%A6.png)
如何使得括号精确地定位在点(a)和(b)的坐标上?
\documentclass[6pt]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{angles,backgrounds,calc,arrows.meta,
decorations.pathreplacing,intersections,
patterns,positioning,quotes}
\usepackage{mathtools}
\begin{document}
\begin{tikzpicture}[thick,>=stealth,x=2cm]
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\draw(-0.5,0)--(4.5 ,0);
\foreach \x/\xtext in {0/,1/7.4,2/7.5,3/7.6,4/}
\draw(\x,2pt)--(\x,-2pt) node[below] {\xtext};
\draw[<->,red, thick] (1,10pt) -- node[above]{0,1} (2,10pt);
\draw[<->,red, thick] (2,10pt) -- node[above]{0,1} (3,10pt);
\draw[Bracket-Bracket,ultra thick,red](a) -- (b);
\end{tikzpicture}
\end{document}
答案1
您可以shorten ...=-0.5\pgflinewidth
增加红线的长度:
\documentclass[tikz, margin=6pt]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[thick,>=stealth,x=2cm]
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\draw(-0.5,0)--(4.5 ,0);
\foreach \x/\xtext in {0/,1/7.4,2/7.5,3/7.6,4/}
\draw(\x,2pt)--(\x,-2pt) node[below] {\xtext};
\draw[<->,red, thick] (1,10pt) -- node[above]{0,1} (2,10pt);
\draw[<->,red, thick] (2,10pt) -- node[above]{0,1} (3,10pt);
\draw[Bracket-Bracket,ultra thick,red, semitransparent,% in real document remove "semitransparent"
shorten <=-0.5\pgflinewidth, shorten >=-0.5\pgflinewidth] (a) -- (b); % <---
\end{tikzpicture}
\end{document}
附录: 您可以为每一个 prackets 组合定义自己的样式:
\documentclass[tikz, margin=6pt]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}[thick,>=stealth,x=2cm,
B/.style = {Bracket-Bracket,
draw=red, ultra thick,
shorten <=-0.5\pgflinewidth, shorten >=-0.5\pgflinewidth},
BL/.style = {{Bracket[reversed]}-Bracket,
draw=red, ultra thick,
shorten <=-1.5\pgflinewidth, shorten >=-0.5\pgflinewidth},
BR/.style = {Bracket-{Bracket[reversed]},
draw=red, ultra thick,
shorten <=-0.5\pgflinewidth, shorten >=-1.5\pgflinewidth},
Br/.style = {{Bracket[reversed]}-{Bracket[reversed]},
draw=red, ultra thick,
shorten <=-1.5\pgflinewidth, shorten >=-1.5\pgflinewidth}
]
\coordinate (a) at (1,0);
\coordinate (b) at (3,0);
\draw(-0.5,0)--(4.5 ,0);
\foreach \x/\xtext in {0/,1/7.4,2/7.5,3/7.6,4/}
\draw(\x,2pt)--(\x,-2pt) node[below] {\xtext};
\draw[<->,red, thick] (1,10pt) -- node[above]{0,1} (2,10pt);
\draw[<->,red, thick] (2,10pt) -- node[above]{0,1} (3,10pt);
\draw[B] (a) -- (b); % <---
\draw[BL] ([yshift=-8mm] a) -- ([yshift=-8mm] b); % <---
\draw[BR] ([yshift=-12mm] a) -- ([yshift=-12mm] b); % <---
\draw[Br] ([yshift=-16mm] a) -- ([yshift=-16mm] b); % <---
\end{tikzpicture}
\end{document}