3

The following code instructs TikZ to draw three lines on the Cartesian plane. I have a brace under line j between the y-axis and the vertical line \ell_{1}. It and its label interfere with the x-axis and \ell_{1}. I would like them to be drawn over these lines. Also, I would like to add a brace under the drawn brace and its label (also in the direction of line j) between the y-axis and the vertical line \ell_{2}. It should also be in the foreground.

\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}
  • @Alenanno May you help me with this? – Adelyn May 26 '15 at 12:41
3

You can change brace orientation with mirror and position of brace's middle part with aspect.

\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}

enter image description here

2nd Version: stacked braces

As the last command you define are for drawing braces, these braces and corresponding labels are already in foreground. But if you want that background lines don't interfere with labels, fill the labels with some background color (probably white) which cover what's behind them.

\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}

enter image description here

3rd version: stacked braces with space around them.

If you don't find a better solution, you can use a preaction to draw a white thicker brace before the normal black brace. It looks like a brace with some white space around it.

\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}

enter image description here

  • I want the braces "stacked" - the brace for c under the brace for a, which is under line j. I see that you used aspect=.75 so that the typesetting of c would not interfere with the drawing of the vertical line ell_{1}. The way that I want to avoid the interference is by putting the pair of braces in the foreground. Do you know how to make these adjustments? – Adelyn May 26 '15 at 12:37
  • @Adelyn: answer updated – Ignasi May 26 '15 at 14:57
  • 1
    @Adelyn: May be a preaction can help. Look at updated answer. – Ignasi May 26 '15 at 16:50
  • 1
    @Adelyn Page 129. It doesn't say to much there. This syntax if used in several examples in pgfmanual. – Ignasi May 27 '15 at 21:56
  • 1
    @Adelyn. With calc (from page 141), ($(O)+(0,-5mm)$) is supposed to do the same. Although it seems to be some problem with the code because it didn't worked to me. I'll try to look at it later. – Ignasi May 28 '15 at 5:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.