在 TikZ 环境中将表示长度的括号放在前台

在 TikZ 环境中将表示长度的括号放在前台

以下代码指示TikZ在笛卡尔平面上绘制三条线。我在jy 轴和垂直线 之间的线下有一个括号\ell_{1}。它和它的标签与 x 轴和 发生干扰\ell_{1}。我希望它们绘制在这些线上。另外,我想在jy 轴和垂直线 之间绘制的括号及其标签(也在线 的方向上)下方添加一个括号\ell_{2}。它也应该在前景中。

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=30,
    restrict y to domain=-10:30,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = A] {0.5*x};
\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = B] {2*x};
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = C] (5,x);
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = D] (9,x);

%These commands label the lines.
\node[font=\footnotesize] at ($(15,7.5) + ({atan(1/2)}:10pt)$) {$j$};
\node[font=\footnotesize] at ($(15,30) + ({atan(2)}:10pt)$) {$k$};
\node[font=\footnotesize] at ($(5,-10) + (0pt,-10pt)$) {$\ell_{1}$};
\node[font=\footnotesize] at ($(9,-10) + (0pt,-10pt)$) {$\ell_{2}$};


\path[name intersections={of=A and B, by={O}}] node at (O) {};
\path[name intersections={of=A and C, by={Q}}] node at (Q) {};
\path[name intersections={of=A and D, by={R}}] node at (R) {};

\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (O)  -- node[below right=3pt and -1pt]{$a$} (Q);
%\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (O)  -- node[above left=3pt and -1pt]{$c$} (R);


\end{axis}

\end{tikzpicture}

\end{document}

答案1

您可以brace使用 来改变方向,使用 来改变mirror的位置。brace's middle partaspect

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=30,
    restrict y to domain=-10:30,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = A] {0.5*x};
\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = B] {2*x};
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = C] (5,x);
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = D] (9,x);

%These commands label the lines.
\node[font=\footnotesize] at ($(15,7.5) + ({atan(1/2)}:10pt)$) {$j$};
\node[font=\footnotesize] at ($(15,30) + ({atan(2)}:10pt)$) {$k$};
\node[font=\footnotesize] at ($(5,-10) + (0pt,-10pt)$) {$\ell_{1}$};
\node[font=\footnotesize] at ($(9,-10) + (0pt,-10pt)$) {$\ell_{2}$};


\path[name intersections={of=A and B, by={O}}] node at (O) {};
\path[name intersections={of=A and C, by={Q}}] node at (Q) {};
\path[name intersections={of=A and D, by={R}}] node at (R) {};

\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt}] (O)  -- 
    node[above left=2pt and -5pt]{$a$} (Q);
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror, aspect=.75}] (O)  -- 
    node[pos=.75, below right=3pt and -3pt]{$c$} (R);


\end{axis}

\end{tikzpicture}

\end{document}

在此处输入图片描述

第二版:堆叠括号

由于您定义的最后一个命令用于绘制括号,因此这些括号和相应的标签已经在 中foreground。但是如果您希望background线条不会干扰标签,则可以使用fill带有某种背景颜色(可能是白色)的标签来覆盖其后面的内容。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, angles, positioning, intersections, quotes, decorations.markings, backgrounds}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=30,
    restrict y to domain=-10:30,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = A] {0.5*x};
\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = B] {2*x};
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = C] (5,x);
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = D] (9,x);

%These commands label the lines.
\node[font=\footnotesize] at ($(15,7.5) + ({atan(1/2)}:10pt)$) {$j$};
\node[font=\footnotesize] at ($(15,30) + ({atan(2)}:10pt)$) {$k$};
\node[font=\footnotesize] at ($(5,-10) + (0pt,-10pt)$) {$\ell_{1}$};
\node[font=\footnotesize] at ($(9,-10) + (0pt,-10pt)$) {$\ell_{2}$};

\path[name intersections={of=A and B, by={O}}] node at (O) {};
\path[name intersections={of=A and C, by={Q}}] node at (Q) {};
\path[name intersections={of=A and D, by={R}}] node at (R) {};

\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (O)  -- 
    node[below right=2mm and .5mm, fill=white, inner sep=1pt]{$a$} (Q);
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] ([yshift=-5mm]O)  -- 
    node[below right=2mm and .5mm, fill=white, inner sep=1pt]{$c$} ([yshift=-5mm]R);

\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

第三版本:堆叠括号,周围留有空间。

如果你找不到更好的解决方案,你可以使用preaction在正常的黑色括号前绘制一个白色较粗的括号。它看起来就像一个周围有一些白色空间的括号。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings,backgrounds}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{tikzpicture}[
        mybrace/.style={decoration={brace, raise=2pt, amplitude=2pt, mirror}},
        mythickbrace/.style={
            preaction={draw=white, line width=2pt},
            decorate, mybrace}
        ]
\begin{axis}[width=5in,clip=false,axis equal image,
    axis lines=middle,
    xmin=-5,xmax=15,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=30,
    restrict y to domain=-10:30,
    enlargelimits={abs=0.5cm},
    axis line style={latex-latex},
    ticklabel style={font=\tiny,fill=white},
    xtick={\empty},ytick={\empty},
    xlabel style={at={(ticklabel* cs:1)},anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},anchor=south west}
]

\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = A] {0.5*x};
\addplot[latex-latex,samples=2,domain=-5:15,blue,name path = B] {2*x};
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = C] (5,x);
\addplot[latex-latex,samples=2,domain=-10:30,blue,name path = D] (9,x);

%These commands label the lines.
\node[font=\footnotesize] at ($(15,7.5) + ({atan(1/2)}:10pt)$) {$j$};
\node[font=\footnotesize] at ($(15,30) + ({atan(2)}:10pt)$) {$k$};
\node[font=\footnotesize] at ($(5,-10) + (0pt,-10pt)$) {$\ell_{1}$};
\node[font=\footnotesize] at ($(9,-10) + (0pt,-10pt)$) {$\ell_{2}$};


\path[name intersections={of=A and B, by={O}}] node at (O) {};
\path[name intersections={of=A and C, by={Q}}] node at (Q) {};
\path[name intersections={of=A and D, by={R}}] node at (R) {};

\draw[mythickbrace] (O)  -- 
    node[below right=2mm and .5mm, fill=white, inner sep=1pt]{$a$} (Q);

\draw[mythickbrace] ([yshift=-5mm]O)  -- 
    node[below right=2mm and .5mm, fill=white, inner sep=1pt]{$c$} ([yshift=-5mm]R);


\end{axis}

\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容