9

How it looks now

I am trying to draw a parallel line to SN (N is an intersection of SM and AB). And also to add "y" symbol in the center of it (like with the lines near SB and BN).

UPDATE: I have came up with the following solution. Still, it is an absolute madness to create such lines just by choosing coordinates.updated

UPDATE 2: Thank you all for your help! I have finally made the picture i wanted to, the code is provided below! Special thanks to MS-SPO =)

enter image description here

\documentclass[leqno,10pt]{extarticle}
\usepackage{tikz}
\usetikzlibrary{angles}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
    \draw[-] (-2, 0) -- (9.3, 0); \draw (-2, 3) -- (9.3, 3);
  
    \coordinate[label=above:\small $S$] (S) at (-1.7, 3); 
    \coordinate[label=below:\small $M$] (M) at (   5, 0); 
    \coordinate[label=above:\small $B$] (B) at (   2, 3);
    \coordinate[label=below:\small $A$] (A) at (   2, 0); 

    \coordinate[label=below:\small $Q$] (Q) at (   9.3, 0); 


    \draw[name path=ortho] (A) -- (B);
    \draw[name path=diag] (S) -- (M);
    \draw[dash pattern={on 1pt off 2pt on 1pt off 2pt}, name path=diagonal] (S) -- (Q);
    \fill [name intersections={of=ortho and diag}]
        (intersection-1) coordinate (N) circle (1pt)
        node[xshift=5pt,yshift=-10pt] {\small $N$};

    \fill [name intersections={of=ortho and diagonal}]
        (intersection-1) coordinate (L) circle (1pt)
        node[xshift=-5pt,yshift=-5pt] {\small $L$};
    
    \pic[draw, angle radius=2mm] {right angle=N--A--M};
    
    \fill (A) circle (1pt);
    \fill (B) circle (1pt);
    \fill (M) circle (1pt);
    \fill (S) circle (1pt);
    \fill (Q) circle (1pt);


    \draw[|-|] ([shift=(230:2.5mm)] S) -- 
        node[fill=white,inner sep=0.5mm,outer sep=0.5mm] {\small $y$} 
        ([shift=(230:2.5mm)] N);

    \draw[|-|] ([yshift=2.5mm, xshift=2.2mm)] S) --
        node[fill=white,inner sep=0.5mm,outer sep=0.5mm] {\small $c$}
        ([yshift=2.5mm, xshift=-2.2mm)] B);

    \draw[|-|] ([xshift=2.5mm, yshift=-1mm)] B) --
        node[fill=white,inner sep=0.5mm,outer sep=0.5mm] {\small $x$}
        ([xshift=2.5mm, yshift=1mm)] N);

    \draw[|-|] ([xshift=-2.5mm, yshift=-1mm)] B) --
        node[fill=white,inner sep=0.5mm,outer sep=0.5mm] {\small $\varepsilon$}
        ([xshift=-2.5mm, yshift=1.3mm)] L);
\end{tikzpicture}
5
  • Welcome to TSE. Please post a Minimal Working Example, instead of a code snippet. Commented Oct 11, 2023 at 13:29
  • 2
    @JoséCarlosSantos, added
    – Tetiana
    Commented Oct 11, 2023 at 13:34
  • 1
    Is the tkz-euclide package possible for you?
    – pascal974
    Commented Oct 11, 2023 at 14:19
  • @pascal974 haven't used it, but i can use whatever will solve the problem
    – Tetiana
    Commented Oct 11, 2023 at 14:42
  • 1
    Try to check some tutorials. There's almost no need for hardcodes coordinates. You can name nodes and use the as part of a path where TikZ automatically connects the lines to their borders. You name coordinates (you never use) and place nodes (labels) on top of them. Why? You might be interested in a dim line pic. Commented Oct 12, 2023 at 0:43

3 Answers 3

8

Parallel lines can mean a lot and there are multiple ways to create these. Here it looks like you actually want a “dim line”, here's a pic that can do this between two points (separated by --) where dim line distance is the offset for that parallel line. The dim line shadow key is used to prepaint the background of the | arrow tips white to cutout an area for the dim line.

Code

\documentclass[leqno, 10pt]{extarticle}
\usepackage{tikz}
\colorlet{Green}{green!50!black}
\usetikzlibrary{arrows.meta, angles, calc, quotes}
\tikzset{
  math nodes/.style={execute at begin node=$, execute at end node=$},
  small math nodes/.style={node font=\small, math nodes},
  % dim line adapted from https://tex.stackexchange.com/a/688676
  Measure/.tip = {Bar[sep = +0pt +-.5]},
  dim line distance/.initial=.2cm,
  dim line flip/.style={
    dim line distance/.expanded={-(\pgfkeysvalueof{/tikz/dim line distance})}},
  dim line style/.style={very thin, -Measure},
  dim line text/.style={midway, auto=false, inner sep=+.15em},
  dim line shadow/.style={every edge/.append style={preaction={
    line width/.expanded=3*\the\pgflinewidth,color=white,tips,arrows={[round]}}}},
  pics/dim line/.style args={#1--#2}{code={
    \path[path only]($(#1)!\pgfkeysvalueof{/tikz/dim line distance}!90:(#2)$)coordinate(@1)
      --node[dim line text,style/.expand once=\tikzpictextoptions,alias=@]{\tikzpictext}
      ($(#2)!\pgfkeysvalueof{/tikz/dim line distance}!-90:(#1)$)coordinate(@2);
    \path[dim line style, line to, pic actions] (@) edge (@1) edge (@2);}}}
\begin{document}
\tikz[
  dashy/.style={dash pattern=on 1pt off 2pt},
  dot/.style={label={% #1 will be used to place a label/pin at a label
    [shape=circle, inner sep=+0pt, fill, minimum size=+2.5pt, #1]center:}},
  small math nodes, % small math nodes everywhere
  every pin/.append style={inner sep=+.15em},
  pin distance=2mm, angle radius=2mm]
\draw coordinate[dot="S"] (S) at (-1.7, 3)
      coordinate[dot="B"] (B) at ( 2,   3)
      [label position=below] % now the labels come below the dots
      coordinate[dot="A"] (A) at ( 2,   0)
      coordinate[dot="M"] (M) at ( 5,   0)
      coordinate[dot="Q"] (Q) at ( 9.3, 0)
      [quotes mean pin]      % now pins will be created instead of labels
      coordinate[dot="250:L" {pin distance=1mm}] % 250 is the direction of the pin
                              (L) at (intersection of S--Q and A--B)
      coordinate[dot="290:N"] (N) at (intersection of S--M and A--B)
  % draw some lines
  (-2, 0) -- +(right:11.5) (-2, 3) -- +(right:11.5) (A) -- (B)
  % the edges will be painted on top of the dots if we don't specify behind path
  { [behind path]
    (S) edge[      Green] (M)
        edge[dashy, blue] (Q) }
  % right angle pic
  pic[draw] {right angle=M--A--B}
  % and dim line pics
  pic["y"                           ] {dim line=N--S}
  pic["c",   dim line distance=1.5em] {dim line=S--B}
  % dim line shadow paints a white background behind the Bar tips
  pic["x",           Green, dim line shadow] {dim line=B--N}
  pic["\varepsilon", blue,  dim line shadow] {dim line=L--B}
;
\end{document}

Output

enter image description here

1
  • Exactly what i wanted! Thanks a lot!
    – Tetiana
    Commented Oct 12, 2023 at 21:49
9

Here's one way to do it.

Working with your code I suggest a few differences.

calc isn't needed here, while intersections and angles are.

To use intersections, I named those paths ortho and diag. The relevant parts in this quite long statement:

    \fill [name intersections={of=ortho and diag}]% which paths to intersect
        (intersection-1) coordinate (N) circle (1pt)% 1st as (N) etc.
        node[xshift=6pt,yshift=4pt] {N};% putting the label there
  • which paths shall intersect? [name intersections={of=ortho and diag}]
  • what are their coordinates, i.e. the first one? (intersection-1)
  • great: let's store it (intersection-1) coordinate (N)
  • the rest is quite what you had already

From a readers point of view I think those extra lines you introduced don't add visual value, don't make things easier to understand, especially, when the lengths do vary. So, let's make it simple and just put the variables names there. To do so, I redraw a few lines invisibly, just to place the labels (nodes) at the right positions:

    % ~~ SIMPLIFIED: kind of redrawing, just to put the labels ~~
    \draw[draw=none] (S) -- node[above] {c} (B);
    \draw[draw=none] (B) -- node[right] {x} (N);
    \draw[draw=none] (S) -- node[below] {y} (N);

Let's use the angles library to indicate the right angle, as it was made for this:

    % ~~~ marking the right angle ~~~~~~~~~~
    \pic[draw, angle radius=2mm] {right angle=N--A--M};

Finally, when filling the dots first, the colored lines cut into them. To avoid this a simple means is putting them at the end.

result

\documentclass[10pt,border=3mm,tikz]{standalone}
\usetikzlibrary{intersections}%     <<< different !
\usetikzlibrary{angles}%            <<< new

\begin{document}
 \begin{tikzpicture}
    % ~~~ parallels ~~~~~~~~~~~~~~~~~~~~~~
    \draw[-] (-2, 0) -- (9.3, 0); \draw (-2, 3) -- (9.3, 3);
  
    % ~~~ most points ~~~~~~~~~~~~~~~~~~~
    \coordinate[label=above:$S$] (S) at (-1.7, 3); 
    \coordinate[label=below:$M$] (M) at (   3, 0); 
    \coordinate[label=above:$B$] (B) at (   2, 3); 
    \coordinate[label=below:$A$] (A) at (   2, 0); 

    % ~~~ orthogonal ~~~~~~~~~~~~~~~~
    \draw[red, name path=ortho] (A) -- (B);% <<<

    % ~~~ diagonal ~~~~~~~~~~~~~~~~
    \draw[blue, name path=diag] (S) -- (M);% <<<
    
    % ~~~ instersection ~~~~~~~~~~~~~~
    \fill [name intersections={of=ortho and diag}]% which paths to intersect
        (intersection-1) coordinate (N) circle (1pt)% 1st as (N) etc.
        node[xshift=6pt,yshift=4pt] {N};% putting the label there
    
    % ~~ SIMPLIFIED: kind of redrawing, just to put the labels ~~
    \draw[draw=none] (S) -- node[above] {c} (B);
    \draw[draw=none] (B) -- node[right] {x} (N);
    \draw[draw=none] (S) -- node[below] {y} (N);
    
    % ~~~ marking the right angle ~~~~~~~~~~
    \pic[draw, angle radius=2mm] {right angle=N--A--M};
    
    % ~~~ placing remaining circles/dots ~~~~~~~~
    \fill (A) circle (1pt);
    \fill (B) circle (1pt);
    \fill (M) circle (1pt);
    \fill (S) circle (1pt);
 \end{tikzpicture}
\end{document}

P.S.: If you insist on adding those parallels - and make reading even harder - here's a way to do it:

    % ~~~ one parallel ~~~~~~~~~~~
    \draw[|-|] ([shift=(230:5mm)] S) -- node[fill=white] {y} ([shift=(230:5mm)] N);
  • use S and N
  • shift their coordinates given as a polar coordinate
  • \draw[|-|] ... for the end-ticks

with parallel

And for all of them do it e.g. this way:

all

    
    % ~~~ all parallels ~~~~~~~~~~~
    \draw[|-|] ([shift=(230:5mm)] S) -- node[fill=white] {y} ([shift=(230:5mm)] N);
    \draw[|-|] ([yshift=7mm)] S)     -- node[fill=white] {c} ([yshift=7mm)] B);
    \draw[|-|] ([xshift=12mm)] B)    -- node[fill=white] {x} ([xshift=12mm)] N);

8
  • Hello. This doesn't exactly answer the "parallel line" question.
    – anis
    Commented Oct 11, 2023 at 15:29
  • "(...) From a readers point of view I think those extra lines you introduced don't add visual value, (...)" // Not all requirements are good ones ;-)
    – MS-SPO
    Commented Oct 11, 2023 at 15:31
  • 1
    Tip with right angle is quite useful, so thanks anyway!
    – Tetiana
    Commented Oct 11, 2023 at 15:37
  • 1
    @MS-SPO thank you so much! it helped a lot
    – Tetiana
    Commented Oct 11, 2023 at 18:38
  • 1
    @MS-SPO, i have finally made what i wanted to! thanks again!
    – Tetiana
    Commented Oct 12, 2023 at 10:26
7

To start...

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}


\begin{document}

\begin{tikzpicture}
    \tkzDefPoints{2/0/A,2/3/B,3/0/M,-1.7/3/S}
    \tkzDrawPoints(A,B,M,S)
    \tkzDrawPoints(A,B,M,S)
    \tkzLabelPoints(A,M)
    \tkzLabelPoints[above](B,S)
    \tkzDrawSegments(A,B M,S)
    \tkzInterLL(A,B)(M,S)\tkzGetPoint{N}
    \tkzDrawPoint[red](N)
    \tkzDrawSegment[
        dim={$x$,5mm,right=2mm},
        dim style/.append style={blue}](B,N)
    \tkzDrawSegment[
        dim={$y$,5mm,left=2mm},
        dim style/.append style={blue}](N,S)
\end{tikzpicture}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .