5

How can i color an edge or a line in TikZ with multiple colors? I'd actually like the color to be displayed "in parallel". Consider the following code:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\tikzstyle arrowstyle=[scale=1]
\tikzstyle directed=[postaction={decorate,decoration={markings,
mark=at position .6 with {\arrow[arrowstyle]{stealth}}}}]

\begin{document}
\begin{tikzpicture}
\draw[directed] (-0.5,1)--(0.5,1) node [midway,above,black] {$b^{-1}$};
\draw[directed] (-1,0.5)--(-0.5,1)node [midway,left,black] {$a$};
\draw[directed] (-1,-0.5)--(-1,0.5)node [midway,left,black] {$b$};
\draw[directed] (-0.5,-1)--(-1,-0.5)node [midway,left,black] {$c^{-1}$};
\draw[ultra thick,directed,red] (-0.5,-1)--(0.5,-1)node [midway,below,black]{$d$};

%I'd like the following three both in red and in blue
\draw[ultra thick,directed,red] (1,0.5)--(0.5,1)node [midway,right,black] {$a$};
\draw[ultra thick,directed,red] (0.5,-1)--(1,-0.5)node [midway,right,black] {$c^{-1}$};
\draw[ultra thick,directed,red] (1,-0.5)--(1,0.5) node [midway,right,black] {$d^{-1}$};

\draw[ultra thick,directed,red] (-1,-1.5)--(-0.5,-1) node[midway,left,black] {$a^{-1}$};
\draw[ultra thick,directed,red](-1,-2.5)--(-1,-1.5) node [midway,left,black] {$b^{-1}$};
\draw[ultra thick,directed,red] (-0.5,-3)--(-1,-2.5) node[midway,left,black] {$a$};
\draw[directed] (-0.5,-3)--(0.5,-3) node [midway,below,black] {$b^{-1}$};
\draw[ultra thick,directed,blue] (0.5,-3)--(1,-2.5) node[midway,right,black] {$c$};
\draw[ultra thick,directed,blue] (1,-2.5)--(1,-1.5) node[midway,right,black] {$d$};
\draw[ultra thick,directed,blue] (1,-1.5)--(0.5,-1) node[midway,right,black] {$c^{-1}$};
\end{tikzpicture}
\end{document}

I would like to color the red edges labelled by a, d^{-1}, c^{-1} in the upper octagon both in red and in blue. How can I do that?

1 Answer 1

5

One way of doing this is to draw the lines in blue and clip them in half.

You can use \clip[draw] to see the clipping rectangle.

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{decorations.markings}
\tikzstyle arrowstyle=[scale=1]
\tikzstyle directed=[postaction={decorate,decoration={markings,
mark=at position .6 with {\arrow[arrowstyle]{stealth}}}}]

\begin{document}
\begin{tikzpicture}
\draw[directed] (-0.5,1)--(0.5,1) node [midway,above,black] {$b^{-1}$};
\draw[directed] (-1,0.5)--(-0.5,1)node [midway,left,black] {$a$};
\draw[directed] (-1,-0.5)--(-1,0.5)node [midway,left,black] {$b$};
\draw[directed] (-0.5,-1)--(-1,-0.5)node [midway,left,black] {$c^{-1}$};
\draw[ultra thick,directed,red] (-0.5,-1)--(0.5,-1)node [midway,below,black]{$d$};

%I'd like the following three both in red and in blue
\draw[ultra thick,directed,red] (1,0.5)--(0.5,1)node [midway,right,black] {$a$};
\draw[ultra thick,directed,red] (0.5,-1)--(1,-0.5)node [midway,right,black] {$c^{-1}$};
\draw[ultra thick,directed,red] (1,-0.5)--(1,0.5) node [midway,right,black] {$d^{-1}$};

% draw same lines in blue, but clipped in half
\begin{scope}
\clip (1,0.5) -- (0.5,1) -- (0.6,1.1) -- (1.1,0.6) -- cycle ;
\draw[ultra thick,directed,blue] (1,0.5)--(0.5,1);
\end{scope}
\begin{scope}
\clip (0.5,-1)--(1,-0.5) -- (1.1,-0.6) -- (0.6,-1.1) -- cycle ;
\draw[ultra thick,directed,blue] (0.5,-1)--(1,-0.5);
\end{scope}
\begin{scope}
\clip (1,-0.5) -- (1,0.5) -- (1.14,0.5) -- (1.14,-0.5) -- cycle ;
\draw[ultra thick,directed,blue] (1,-0.5)--(1,0.5);
\end{scope}


\draw[ultra thick,directed,red] (-1,-1.5)--(-0.5,-1) node[midway,left,black] {$a^{-1}$};
\draw[ultra thick,directed,red](-1,-2.5)--(-1,-1.5) node [midway,left,black] {$b^{-1}$};
\draw[ultra thick,directed,red] (-0.5,-3)--(-1,-2.5) node[midway,left,black] {$a$};
\draw[directed] (-0.5,-3)--(0.5,-3) node [midway,below,black] {$b^{-1}$};
\draw[ultra thick,directed,blue] (0.5,-3)--(1,-2.5) node[midway,right,black] {$c$};
\draw[ultra thick,directed,blue] (1,-2.5)--(1,-1.5) node[midway,right,black] {$d$};
\draw[ultra thick,directed,blue] (1,-1.5)--(0.5,-1) node[midway,right,black] {$c^{-1}$};
\end{tikzpicture}
\end{document}

enter image description here

0

You must log in to answer this question.

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