Tikz - 图形现有边之间的阴影区域

Tikz - 图形现有边之间的阴影区域

我有由下面给出的代码生成的图表。

在此处输入图片描述

\begin{tikzpicture}[node distance={25mm}, thick, main/.style = {draw, circle}]
\node[main] (1) {$11$};
\node[main] (2) [right of=1] {$12$};
\node[main] (3) [right of=2] {$13$};
\node[main] (4) [above of=1] {$21$};
\node[main] (5) [right of=4] {$22$}; 
\node[main] (6) [right of=5] {$23$};


% Horizontal down
\draw [->, red] (1) -- node[below]{$2$} (2);
\draw [<-, red] (2) -- node[below]{$1$} (3);

% Curve down
\draw [->, red] (1) to [out = -90, in = -90 ] node[below]{$1$} (3);

% Horizontal up
\draw [<-, red] (4) -- node[above]{$2$} (5);
\draw [->, red] (5) -- node[above]{$1$} (6);

% Curve up
\draw [<-, red] (4) to [out = 90, in = 90 ] node[above]{$1$} (6);

% Vertical
\draw [<-, blue] (1) -- node[left]{$3$} (4);
\draw [->, blue] (2) -- node[left]{$3$} (5);
\draw [->, blue] (3) -- node[right]{$0$} (6);
\end{tikzpicture}

我怎样才能遮蔽红色边缘所划定的区域,以获得类似这样的效果? 在此处输入图片描述

答案1

您可以使用backgrounds库来绘制填充区域。但您还必须用白色(或任何页面颜色)填充节点。

此外,没有使用该positioning库和语法[right=of 1]

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{backgrounds, positioning}

\begin{document}

\begin{tikzpicture}[node distance={25mm}, thick, main/.style = {draw, circle, fill=white}]
\node[main] (1) {$11$};
\node[main] (2) [right =of 1] {$12$};
\node[main] (3) [right =of 2] {$13$};
\node[main] (4) [above =of 1] {$21$};
\node[main] (5) [right =of 4] {$22$}; 
\node[main] (6) [right =of 5] {$23$};
% fill
\begin{scope}[on background layer]
\fill[gray!30] (1.center)--(3.center)--(3.south) to[out = -90, in = -90 ] (1.south) -- (1.center);
\fill[gray!30] (4.center)--(6.center)--(6.north) to[out = 90, in = 90 ] (4.north) -- (1.center);
\end{scope}

% Horizontal down
\draw [->, red] (1) -- node[below]{$2$} (2);
\draw [<-, red] (2) -- node[below]{$1$} (3);

% Curve down
\draw [->, red] (1) to [out = -90, in = -90 ] node[below]{$1$} (3);

% Horizontal up
\draw [<-, red] (4) -- node[above]{$2$} (5);
\draw [->, red] (5) -- node[above]{$1$} (6);

% Curve up
\draw [<-, red] (4) to [out = 90, in = 90 ] node[above]{$1$} (6);

% Vertical
\draw [<-, blue] (1) -- node[left]{$3$} (4);
\draw [->, blue] (2) -- node[left]{$3$} (5);
\draw [->, blue] (3) -- node[right]{$0$} (6);

\end{tikzpicture}

\end{document}

相关内容