5

I would like to label the length of four line segments in a certain plot. In the plot, the length of line segment PQ should be labeled a, the length of line segment QS should be labeled b, the length of line segment PR should be labeled ``c, and the length of line segment RT should be labeled d.

The label for a can be placed in the middle of a line segment parallel to and just below line k (containing points P, Q, and R). I saw on this web site that the command \draw[|<->|] is used for this display. The label for a can also be placed below a { that is drawn below the line segment PQ. I did not see in the TikZ manual how to do this.

Also, I would like the line segment or { that is used to indicate the lengths of line segment PQ and PR to be placed on top of the plot - so that there is some white space about it. The axes and lines \ell_{1} and \ell_{2} would interfere without placing the line segment or { on top.

\documentclass{amsart}
\usepackage{tikz}

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


\begin{document}


\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-13,xmax=13,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=18,
    restrict y to domain=-10:18,
    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=-13:13,blue] {x + 3} node[below, pos=0.1,font=\footnotesize]{$j$};
\addplot[latex-latex,samples=2,domain=-13:13,blue] {0.5*x + 1} node[above, pos=0.1,font=\footnotesize]{$k$};
\addplot[latex-latex,samples=2,domain=-4:10,blue] {2*x - 2} node[above left, pos=0.05,font=\footnotesize]{$\ell_{1}$};
\addplot[latex-latex,samples=2,domain=-1:13,blue] {2*x - 8} node[above left, pos=0.05,font=\footnotesize]{$\ell_{2}$};
\draw [fill] (-4,-1) circle [radius=1pt] node[below]{$P$};
\draw [fill] (2,2) circle [radius=1pt] node[below right]{$Q$};
\draw [fill] (6,4) circle [radius=1pt] node[below right]{$R$};
\draw [fill] (5,8) circle [radius=1pt] node[above left]{$S$};
\draw [fill] (11,14) circle [radius=1pt] node[above left]{$T$};
\end{axis}
\end{tikzpicture}
\hspace*{\fill}
\vskip0.25in

\end{document}
  • 1
    Please, ask only one question per question. – Paul Gessler Apr 5 '15 at 0:17
  • 1
    Well you can start asking one question also. You want to do these things but what is the problem that you cannot go further? – percusse Apr 5 '15 at 0:28
  • @percusse I said that I did not know the command to have a brace displayed in a plot. – Adelyn Apr 5 '15 at 15:33
3

Here is the brace version.

\documentclass{amsart}
\usepackage{tikz}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{intersections,decorations.pathreplacing,positioning}

\begin{document}


\noindent 
\begin{tikzpicture}
\begin{axis}[width=5in,axis equal image,
    axis lines=middle,
    xmin=-13,xmax=13,samples=2,
    xlabel=$x$,ylabel=$y$,
    ymin=-10,ymax=18,
    restrict y to domain=-10:18,
    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=-13:13,blue,name path = A] {x + 3} node[below, pos=0.1,font=\footnotesize]{$j$};
\addplot[latex-latex,samples=2,domain=-13:13,blue,name path = B] {0.5*x + 1} node[above, pos=0.1,font=\footnotesize]{$k$};
\addplot[latex-latex,samples=2,domain=-4:10,blue,name path = C] {2*x - 2} node[above left, pos=0.05,font=\footnotesize]{$\ell_{1}$};
\addplot[latex-latex,samples=2,domain=-1:13,blue,name path = D] {2*x - 8} node[above left, pos=0.05,font=\footnotesize]{$\ell_{2}$};
\path[name intersections={of=A and B, by={a}}]
  node[fill,circle,inner sep=1pt,label=below:$P$] at (a) {};
\path[name intersections={of=B and C, by={b}}]
  node[fill,circle,inner sep=1pt,label=below right:$Q$] at (b) {};
\path[name intersections={of=B and D, by={c}}]
  node[fill,circle,inner sep=1pt,label=below right:$R$] at (c) {};
\path[name intersections={of=A and C, by={d}}]
  node[fill,circle,inner sep=1pt,label=above left:$S$] at (d) {};
\path[name intersections={of=A and D, by={e}}]
  node[fill,circle,inner sep=1pt,label=above left:$T$] at (e) {};

\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (a)  -- node[below right=3pt and -1pt]{a} (b) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt}] (a)  -- node[above left=3pt and -1pt]{c} (c) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (b)  -- node[right=3pt]{b} (d) ;
\draw[decorate,decoration={brace,raise=2pt,amplitude=2pt,mirror}] (c)  -- node[right=3pt]{d} (e) ;
\end{axis}
\end{tikzpicture}

\end{document}

I have used intersections library and hence no manual guessing of point of intersections.

enter image description here

With

\draw[latex-latex,blue] (a)  -- node[fill=white,inner ysep=0pt]{a} (b) ;
\draw[latex-latex,blue] ([shift={(-3pt,5pt)}]a)  -- node[fill=white,inner sep=1.8pt]{c} ([shift={(-3pt,5pt)}]c) ;
\draw[latex-latex,blue] (b)  -- node[fill=white]{b} (d) ;
\draw[latex-latex,blue] (c)  -- node[fill=white]{d} (e) ;

enter image description here

| improve this answer | |
  • I like that you used the intersections command. With the added braces to the plot, I see that I will have to move the points further from the axes, and using the intersections command will keep me from tedious computations. – Adelyn Apr 5 '15 at 17:58
  • There is one important modification that I need to your code - the code using the braces. I would like the braces placed "over" the plot of all lines, including the axes. The manifestation of this is white space surrounding the brace. I replaced one line of your code with \draw [decorate,decoration={brace,raise=15pt,amplitude=4pt,mirror}] (a) -- node[below right=16pt,align=center,midway]{$c$} (c);. With this code, the "c" is not centered. – Adelyn Apr 5 '15 at 18:05
  • The option below right is appropriate for labeling points Q and R. How do I get them closer to the points? – Adelyn Apr 5 '15 at 18:21
  • @Adelyn Make inner sep zero with label={[inner sep=0pt]below right:$R$} – user11232 Apr 5 '15 at 23:09
  • Thanks. Do you know what the default separation is? How far is P from the point it labels? Do you know how to put the braces "over" the plot? – Adelyn Apr 6 '15 at 0:17
3

A try for the “braces version”, with MetaPost. The version with arrows will hopefull come soon.

The mkbrace macro, at the basis of the braces drawn here, has been borrowed from the mfpic package and has been devised by Dan Luecking, its current maintainer.

To be typeset with LuaLaTeX.

\documentclass[12pt, border=5mm]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    % Creates a brace between points S and E with cusp placed in C
    % Borrowed from the mfpic package, by Dan Luecking
    vardef mkbrace (expr S, C, E) =
      save R_, U_, V_, Z_;
      pair U_, V_, Z_[];
      U_ := unitvector (E-S);
      V_ := U_ rotated 90;
      R_ := 0.5*(C-S) dotprod V_;
      if R_ = 0:
        S--C
      else:
        if R_ < 0 :  V_ := -V_; R_ := -R_;  fi
        V_ := R_*V_; U_ := R_*U_;
        Z_1 := S + V_ + U_;
        Z_2 := C - V_ - U_;
        Z_3 := C - V_ + U_;
        Z_4 := E + V_ - U_;
        S{V_}..{U_}Z_1--Z_2{U_}..{V_}C{-V_}..{U_}Z_3--Z_4{U_}..{-V_}E
      fi
    enddef;

    hcusp := 2mm;
    vardef drawbrace (expr p, str) =
      save S, C, E; pair S, C, E;
      S = point 0 of p; E = point 1 of p; 
      C = .5[S,E] shifted (hcusp*unitvector((E-S) rotated 90));
      draw mkbrace(S, C, E);
      freelabeloffset := 1bp;
      freelabel(str, C, .5[S, E]);
    enddef;

    vardef bigline(text f) =
      (xmin, hide(x := xmin) f) -- (xmax, hide(x := xmax) f)
    enddef;

    u := .5cm;
    xmin := -13; xmax := 13; ymin := -10; ymax := 18;

    path sup_border; sup_border = (xmin, ymax) -- (xmax, ymax);
    path inf_border; inf_border = (xmin, ymin) -- (xmax, ymin);

    beginfig(1);
      drawarrow (xmin*u, 0) -- (xmax*u, 0); label.bot("$x$", (xmax*u, 0));
      drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0, ymax*u));

      path PQ, PS, QS, RT;
      PQ = bigline(.5x + 1) scaled u; 
      PS = bigline(x + 3) scaled u;
      QS = (bigline(2x - 2) cutbefore inf_border cutafter sup_border) scaled u;
      RT = (bigline(2x - 8) cutbefore inf_border cutafter sup_border) scaled u;

      pair P, Q, R, S, T;
      P = PQ intersectionpoint PS;
      Q = PQ intersectionpoint QS;
      R = PQ intersectionpoint RT;
      S = PS intersectionpoint QS;
      T = PS intersectionpoint RT;

      drawoptions(withcolor blue);
      for line = PQ, PS, QS, RT: draw line; endfor;
      labeloffset := 5bp;
      label.top("$k$", point cm on PQ);
      label.bot("$j$", point cm on PS);
      label.lft("$\ell_1$", point 1cm on QS);
      label.lft("$\ell_2$", point 1cm on RT);

      drawoptions();
      for point = P, Q, R, S, T:
        drawdot point withpen pencircle scaled 3bp;
      endfor;
      labeloffset := 3bp;
      label.bot("$P$", P); label.lrt("$Q$", Q); label.bot("$R$", R);
      label.ulft("$S$", S); label.ulft("$T$", T);

      hcusp := -4mm;
      drawbrace (P--Q, "$a$"); drawbrace (Q--S, "$b$"); drawbrace (R--T, "$d$");
      hcusp := 4mm;
      drawbrace (P--R, "$c$");
    endfig;
  \end{mplibcode}  
\end{document}

enter image description here

And now with the arrows (inspired by Harish Kumar's answer).

\documentclass[12pt, border=2bp]{standalone}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
\begin{document}
  \begin{mplibcode}
    def clear(expr pict) = unfill bbox pict; draw pict; enddef;

    vardef drawdoublearrow(expr pat, str) =
      save A, B, v; pair A, B; 
      A = point 0 of pat; B = point 1 of pat;
      drawdblarrow A--B;
      clear(thelabel(str, .5[A,B]));
    enddef;

    hoffset := 3mm;
    vardef drawbarends(expr pat, str) =
        save A, B, v; pair A, B, v; 
        v = hoffset*(unitvector(point 1 of pat - point 0 of pat) rotated 90);
      A = point 0 of pat shifted v;
      B = point 1 of pat shifted v;
        drawdblarrow A -- B;
        for M = A, B:
          draw M+v -- M-v;
        endfor;
        clear(thelabel(str, .5[A,B]));
    enddef;

    vardef bigline(text f) =
      (xmin, hide(x := xmin) f) -- (xmax, hide(x := xmax) f)
    enddef;

    u := .5cm;
    xmin := -13; xmax := 13; ymin := -10; ymax := 18;

    path sup_border; sup_border = (xmin, ymax) -- (xmax, ymax);
    path inf_border; inf_border = (xmin, ymin) -- (xmax, ymin);

    beginfig(1);
      drawarrow (xmin*u, 0) -- (xmax*u, 0); label.bot("$x$", (xmax*u, 0));
      drawarrow (0, ymin*u) -- (0, ymax*u); label.lft("$y$", (0, ymax*u));

      path PQ, PS, QS, RT;
      PQ = bigline(.5x + 1) scaled u; 
      PS = bigline(x + 3) scaled u;
      QS = (bigline(2x - 2) cutbefore inf_border cutafter sup_border) scaled u;
      RT = (bigline(2x - 8) cutbefore inf_border cutafter sup_border) scaled u;

      pair P, Q, R, S, T;
      P = PQ intersectionpoint PS;
      Q = PQ intersectionpoint QS;
      R = PQ intersectionpoint RT;
      S = PS intersectionpoint QS;
      T = PS intersectionpoint RT;

      drawoptions(withcolor blue);
      for line = PQ, PS, QS, RT: draw line; endfor;
      labeloffset := 5bp;
      label.top("$k$", point cm on PQ);
      label.bot("$j$", point cm on PS);
      label.lft("$\ell_1$", point 1cm on QS);
      label.lft("$\ell_2$", point 1cm on RT);

      drawoptions();
      labeloffset := 3bp;
      label.bot("$P$", P); label.lrt("$Q$", Q); label.bot("$R$", R);
      label.ulft("$S$", S); label.ulft("$T$", T);

      drawdoublearrow (P--Q, "$a$"); drawdoublearrow (Q--S, "$b$"); 
      drawdoublearrow (R--T, "$d$"); drawbarends(P--R, "$c$");
    endfig;
  \end{mplibcode}  
\end{document}

enter image description here

| improve this answer | |
  • These plots are nice ... but I wanted the code only using TikZ and 'pgfplots'. – Adelyn Apr 5 '15 at 15:48
  • 1
    @Adelyn Harish Kumar's very nice answer is what you want. I wouldn't have answered myself if someone else hadn't with the packages you required. Complementary answers using other drawing middles than the one required by the OP are usually encouraged here. They should be taken as they are meant: as a (hopefully) useful information about how the problem can be tackled by other means. I am sorry if mine bothered you. – Franck Pastor Apr 5 '15 at 16:30

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.