1

I'm trying to draw a red line along the existing path:

enter image description here

Here is my code:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\tikz{
  \node[circle,draw] (v1) {};
  \node[circle,draw,below right of=v1] (v2) {};
  \path[draw] (v1) -- (v2);
}
\end{document}

How can I add the red line to it?

1 Answer 1

2

You can add a pic for that.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[pics/parallel arrow/.style={code={
    \draw[-latex] (-#1) -- (#1);}}]
  \node[circle,draw] (v1) {};
  \node[circle,draw,below right of=v1] (v2) {};
  \path[draw] (v1) -- 
    pic[sloped,red,semithick,auto,swap]{parallel arrow={0.3,-0.15}} (v2);
\end{tikzpicture}
\end{document}

enter image description here

3
  • The length of the red arrow is the same as the length of the black line, correct? Is it possible to make it shorter, like in my example?
    – yegor256
    Mar 31, 2021 at 15:01
  • add the option shorten to the arrow code
    – js bibra
    Mar 31, 2021 at 15:09
  • 1
    @yegor256 It has the same length by accident. If you replace 0.3 by 0.25 it will become shorter. Similarly, if you replace 0.2 by 0.15 the arrow will be closer to the line.
    – user238301
    Mar 31, 2021 at 15:12

You must log in to answer this question.

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