2

I am trying to draw a double line with different color by tikzpicture like this:

\begin{tikzpicture}
    \draw[red] (0, 0 + .01) -- (1, 0 + .01);
    \draw[blue] (0, 0 - .01) -- (1, 0 - .01);
\end{tikzpicture}

However, it is annoying to calculate the coordinate by myself for each time. Thus is there a way to write a macro for this like:

\tikzstyle{...}

?

3

2 Answers 2

2

The my pen has an argument that indicates the distance of overvaluation in relation to the initial path, which is not drawn.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\tikzset{my pen/.style={
        execute at begin to={\def\hauteur{#1}
        \draw[red] ($(\tikztostart)!\hauteur!90:(\tikztotarget)$) -- ($(\tikztotarget)!\hauteur!-90:(\tikztostart)$);},
        execute at begin to={\draw[blue] ($(\tikztostart)!\hauteur!-90:(\tikztotarget)$) --    ($(\tikztotarget)!\hauteur!90:(\tikztostart)$);},
}} 

\begin{document}
\begin{tikzpicture}
    \draw[my pen=3mm] (0, 1) to (5,2);
    
    \draw[my pen=1mm] (0, 0) to (5,0);
\end{tikzpicture}
\end{document}

enter image description here

0

Like that:

\documentclass{standalone}
\usepackage{tikz}

\tikzset{
linea_roja/.style = {draw=red, thick = 1pt},
linea_azul/.style = {draw=blue, thick = 1pt}}


\begin{document}
   \begin{tikzpicture}
        \draw[linea_roja] (0,0.1) -- (5,0.1) + (2pt,0);
        \draw[linea_azul] (0,0) -- (5,0) + (2pt,0);
    \end{tikzpicture}
\end{document} 

You must log in to answer this question.

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