3

The following code is rendered to depict three parallel lines k, \ell, and m, and two traversals s and t. The intersections of k, \ell, and m and s are called A, B, and C, respectively. (The labels for these points are not displayed.) I have labeled the length of the line segment AB as x + 5 and the length of the line segment BC at 4x + 5.

There are two modifications that I would like to have. First, I would like the labels x + 5 and 4x + 5 to be half as far from the line below them as the line above them. (The horizontal lines are "stacked" with k on top and m on bottom. So, the points A, B, and C are stacked with A on top and C on bottom.) Second, I would like the nodes for x + 5 and 4x + 5 typeset in the same direction as the lines k, \ell, and m. Here is the command that I used to typeset 4x + 5, for example. I also have a green line drawn to illustrate where I want the node. It illustrates the slight error in placement of the node.

\node[anchor=15, inner sep=0, rotate=15, font=\footnotesize] at ($($(B)!{2/3}!(C)$) +(195:0.3)$){$4x+5$};

\draw[line width=0.2pt, green] ($(B)!{2/3}!(C)$) -- ($($(B)!{2/3}!(C)$) +({195}:2)$);

All four node commands are at the end of the code.

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amsfonts}

\usepackage{tikz}
\usetikzlibrary{calc,positioning,intersections,quotes,decorations.markings,decorations.pathreplacing,}


\begin{document}


\begin{tikzpicture}

%Three parallel lines k, \ell, and m are drawn. Two traversals s and t are to be drawn.
%The ratios of the lengths of the line segments along the traversals between k and \ell
%to the lengths of the line segments along the traversals between \ell and m is to be
%3 to 2.
%
%A, B, and C are points on t; C is a point on line m, B is a point on line ell, and A is
%a point on line k.  P, Q, and R are points on s; R is a point on line m, Q is a point
%on line ell, and P is a point on line k. The length of line segment AB is 6, and the
%length of line segment BC is 9. To maintain the same ratio between corresponding points
%on line s, a circle of radius 6 about R is drawn and one of the intersections with line
%ell is labeled Q, and a circle of radius 4 about Q is drawn and one of the intersections
%with line k is labeled P.
\path[name path=line_m] (0,0) -- (15:15);
\coordinate (C) at (15:5);
\coordinate (R) at (15:12);
\coordinate (B) at ($(C) +(50:2.25)$);
\path[name path=line_ell, latex-latex] ($(B) +(195:3)$) -- ($(B) +(15:12)$);
\path[name path=circular_arc_to_locate_Q] (R) circle (1.5);
\coordinate[name intersections={of=line_ell and circular_arc_to_locate_Q}];
\coordinate (Q) at (intersection-2);
\coordinate (A) at ($(B) +(50:1.5)$);
\path[name path=line_k, latex-latex] ($(A) +(195:3)$) -- ($(A) +(15:9)$);
\path[name path=circular_arc_to_locate_P] (Q) circle (1);
\coordinate[name intersections={of=line_k and circular_arc_to_locate_P}];
\coordinate (P) at (intersection-2);

\draw[latex-latex] ($(C) +(195:3)$) -- ($(R) +(15:2)$);
\node[anchor=195, inner sep=0] at ($(R) +(15:2) +(15:0.15)$){$m$};
\draw[latex-latex] ($(B) +(195:3)$) -- ($(Q) +(15:2)$);
\node[anchor=195, inner sep=0] at ($(Q) +(15:2) +(15:0.15)$){$\ell$};
\draw[latex-latex] ($(A) +(195:3)$) -- ($(P) +(15:2)$);
\node[anchor=195, inner sep=0] at ($(P) +(15:2) +(15:0.15)$){$k$};


%Traversals s and t are drawn. Invisible lines parallel to k, \ell, and m
%that pass through the arrowheads of s are used to bound t.
\draw[name path=path_for_traversal_t, latex-latex] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(R) +(\n1:1)$) -- ($(P) +({\n1-180}:1)$);
\draw let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-180}, inner sep=0] at ($($(R) +(\n1:1)$) +(\n1:0.15)$){$t$};

\path[name path=path_for_traversal_s] ($(C) +(-130:2)$) -- ($(A) + (50:2)$);
\path[name path=path_for_the_lower_arrowhead_of_s] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(R) +(\n1:1)$) -- ($(R) +(\n1:1) +(195:11)$);
\path[name path=path_for_the_upper_arrowhead_of_s] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(P) +({\n1-180}:1)$) -- ($(P) +({\n1-180}:1) +(195:7)$);
\coordinate[name intersections={of=path_for_traversal_s and path_for_the_lower_arrowhead_of_s, by={lower_arrowhead_for_s}}];
\coordinate[name intersections={of=path_for_traversal_s and path_for_the_upper_arrowhead_of_s, by={upper_arrowhead_for_s}}];
\draw[latex-latex] (lower_arrowhead_for_s) -- (upper_arrowhead_for_s);
\draw let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor=50, inner sep=0] at ($(lower_arrowhead_for_s) +(-130:0.15)$){$s$};


%The lengths of the line segments on the traversals between the parallel lines are typeset.
\node[anchor=15, inner sep=0, rotate=15, font=\footnotesize] at ($($(A)!0.5!(B)$) +(195:0.3)$){$x+5$};
\draw[line width=0.2pt, green] ($(A)!0.5!(B)$) -- ($($(A)!0.5!(B)$) +({195}:2)$);
\node[anchor=15, inner sep=0, rotate=15, font=\footnotesize] at ($($(B)!0.5!(C)$) +(195:0.3)$){$4x+5$};
\draw[line width=0.2pt, green] ($(B)!0.5!(C)$) -- ($($(B)!0.5!(C)$) +({195}:2)$);
\draw node[anchor=195, inner sep=0, rotate=15, font=\footnotesize] at ($($(P)!0.5!(Q)$) +(15:0.3)$){$4$};
\draw[line width=0.2pt, green] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(P)!0.5!(Q)$) -- ($($(P)!0.5!(Q)$) +(15:2)$);
\draw node[anchor=195, inner sep=0, rotate=15, font=\footnotesize] at ($($(Q)!0.5!(R)$) +(15:0.3)$){$6$};
\draw[line width=0.2pt, green] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(Q)!0.5!(R)$) -- ($($(Q)!0.5!(R)$) +(15:2)$);

\end{tikzpicture}

\end{document}
  • Try \node[sloped,...] {...}. – Zarko Nov 28 '15 at 17:23
  • @Zarko I did try that. To use sloped, you have be be using a path command, I think. – user74973 Nov 28 '15 at 17:24
2

Something like this?

[EDITED to use 1/3 rather than 1/2 as I initially misread the desiderata in the question.]

sloped labels

\documentclass[tikz]{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usetikzlibrary{calc,positioning,intersections,quotes,decorations.markings,decorations.pathreplacing,}
\begin{document}
  \begin{tikzpicture}
    %Three parallel lines k, \ell, and m are drawn. Two traversals s and t are to be drawn.
    %The ratios of the lengths of the line segments along the traversals between k and \ell
    %to the lengths of the line segments along the traversals between \ell and m is to be
    %3 to 2.
    %
    %A, B, and C are points on t; C is a point on line m, B is a point on line ell, and A is
    %a point on line k.  P, Q, and R are points on s; R is a point on line m, Q is a point
    %on line ell, and P is a point on line k. The length of line segment AB is 6, and the
    %length of line segment BC is 9. To maintain the same ratio between corresponding points
    %on line s, a circle of radius 6 about R is drawn and one of the intersections with line
    %ell is labeled Q, and a circle of radius 4 about Q is drawn and one of the intersections
    %with line k is labeled P.
    \path[name path=line_m] (0,0) -- (15:15);
    \coordinate (C) at (15:5);
    \coordinate (R) at (15:12);
    \coordinate (B) at ($(C) +(50:2.25)$);
    \path[name path=line_ell, latex-latex] ($(B) +(195:3)$) -- ($(B) +(15:12)$);
    \path[name path=circular_arc_to_locate_Q] (R) circle (1.5);
    \coordinate[name intersections={of=line_ell and circular_arc_to_locate_Q}];
    \coordinate (Q) at (intersection-2);
    \coordinate (A) at ($(B) +(50:1.5)$);
    \path[name path=line_k, latex-latex] ($(A) +(195:3)$) -- ($(A) +(15:9)$);
    \path[name path=circular_arc_to_locate_P] (Q) circle (1);
    \coordinate[name intersections={of=line_k and circular_arc_to_locate_P}];
    \coordinate (P) at (intersection-2);

    \draw[latex-latex] ($(C) +(195:3)$) coordinate (c) -- ($(R) +(15:2)$) coordinate (r);
    \node[anchor=195, inner sep=0] at ($(R) +(15:2) +(15:0.15)$){$m$};
    \draw[latex-latex] ($(B) +(195:3)$) coordinate (b) -- ($(Q) +(15:2)$) coordinate (q);
    \node[anchor=195, inner sep=0] at ($(Q) +(15:2) +(15:0.15)$){$\ell$};
    \draw[latex-latex] ($(A) +(195:3)$) coordinate (a) -- ($(P) +(15:2)$) coordinate (p);
    \node[anchor=195, inner sep=0] at ($(P) +(15:2) +(15:0.15)$){$k$};

    %Traversals s and t are drawn. Invisible lines parallel to k, \ell, and m
    %that pass through the arrowheads of s are used to bound t.
    \draw[name path=path_for_traversal_t, latex-latex] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(R) +(\n1:1)$) -- ($(P) +({\n1-180}:1)$);
    \draw let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor={\n1-180}, inner sep=0] at ($($(R) +(\n1:1)$) +(\n1:0.15)$){$t$};

    \path[name path=path_for_traversal_s] ($(C) +(-130:2)$) -- ($(A) + (50:2)$);
    \path[name path=path_for_the_lower_arrowhead_of_s] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(R) +(\n1:1)$) -- ($(R) +(\n1:1) +(195:11)$);
    \path[name path=path_for_the_upper_arrowhead_of_s] let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in ($(P) +({\n1-180}:1)$) -- ($(P) +({\n1-180}:1) +(195:7)$);
    \coordinate[name intersections={of=path_for_traversal_s and path_for_the_lower_arrowhead_of_s, by={lower_arrowhead_for_s}}];
    \coordinate[name intersections={of=path_for_traversal_s and path_for_the_upper_arrowhead_of_s, by={upper_arrowhead_for_s}}];
    \draw[latex-latex] (lower_arrowhead_for_s) -- (upper_arrowhead_for_s);
    \draw let \p1=($(P)-(R)$), \n1={atan(\y1/\x1)} in node[anchor=50, inner sep=0] at ($(lower_arrowhead_for_s) +(-130:0.15)$){$s$};

%   \foreach \i in {A,B,C,P,Q,R,a,b,c,r,q,p} \node at (\i) {\i};

    %The lengths of the line segments on the traversals between the parallel lines are typeset.
    \draw node[inner sep=0] at ($($(P)!0.3!90:(Q)$)!{2/3}!($(Q)!0.3!-90:(P)$)$) {$4$};
    \draw node[inner sep=0] at ($($(Q)!0.3!90:(R)$)!{2/3}!($(R)!0.3!-90:(Q)$)$) {$6$};
    \path ($(a)!2/3!(b)$) -- ($(p)!2/3!(q)$) node [pos=.25, sloped] {$x+5$};
    \path ($(b)!2/3!(c)$) -- ($(q)!2/3!(r)$) node [pos=.2, sloped] {$4x+5$};
  \end{tikzpicture}
\end{document}

Note that if you really want the labels centred on the green line, you should use 1/2 rather than 2/3:

    \path ($(a)!.5!(b)$) -- ($(p)!.5!(q)$) node [pos=.25, sloped] {$x+5$};
    \path ($(b)!.5!(c)$) -- ($(q)!.5!(r)$) node [pos=.2, sloped] {$4x+5$};

    \draw[line width=0.2pt, green] ($(B)!0.5!(C)$) -- ($($(B)!0.5!(C)$) +({195}:2)$);

zoom on green line

Alternatively, you could rotate the nodes, but this seemed easier. If you want to use this, you can just use rotate=<angle> in the options to the node. For example:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \foreach \i [count=\j] in {0,30,60,...,330}
    \node [rotate=\i, draw] at (2*\j,0) {angle \i};
  \end{tikzpicture}
\end{document}

rotated nodes

  • Yes, that is the diagram that I want. Actually, the directions were to have x + 5 half the distance from line \ell as it is from line k and to have 4x + 5 half the distance from line m as it is from line \ell. I guess that I replace 0.5! in your code with {1/3}!. Why didn't my code give me that? – user74973 Nov 28 '15 at 18:08
  • I see that \coordinate (a), \coordinate (b), and \coordinate (c) are the left arrowheads of lines k, \ell, and m, respectively, and that \coordinate (p), \coordinate (q), and \coordinate (r) are the right arrowheads of lines k, \ell, and m, respectively. So, in your path command \path ($(a)!.5!(b)$) -- ($(p)!.5!(q)$) node [pos=.25, sloped] {$x+5$};, the start is halfway between the left arrowheads of k and \ell, and the end is halfway between the right arrowheads of k and \ell. I understand the issuance of this command. – user74973 Nov 28 '15 at 19:09
  • Please give me the code for rotating a node. That may be more convenient for me. – user74973 Nov 28 '15 at 19:09
  • Oh, I misread it. Yes, you can say 1/3 for 0.5. I did it quickly while taking a break. – cfr Nov 28 '15 at 20:24
  • 1
    But it is hard to say why something isn't. The question, really, is why you think it should be the right specification. – cfr Nov 29 '15 at 0:45

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.