括号放置的精确度

括号放置的精确度

如何使得括号精确地定位在点(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}

在此处输入图片描述

相关内容