TikZ 中的多种颜色边缘

TikZ 中的多种颜色边缘

如何使用多种颜色为 TikZ 中的边或线着色?我实际上希望颜色“并行”显示。请考虑以下代码:

\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}

我想将上八边形中标记为ad^{-1}的红色边缘涂c^{-1}成红色和蓝色。我该怎么做?

答案1

一种方法是用蓝色画出线条,然后将其剪成两半。

您可以使用\clip[draw]来查看剪辑矩形。

\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}

在此处输入图片描述

相关内容