如何用 tikz 绘制不规则阴影区域?

如何用 tikz 绘制不规则阴影区域?

我怎样才能用 tikz 绘制不规则阴影区域和(类似地?)像图像中那样的节点周围的不规则框架?

博弈分析

答案1

为 Carol 提供的简单快捷的示例

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,shapes.geometric,calc,backgrounds}
\begin{document}
\begin{tikzpicture}
\matrix (gamea) [matrix of nodes,nodes={circle,draw},row sep=5mm,column sep=5mm]{
 & 1 &\\
 2& |[draw=none]|3 & 4\\
 |[draw=none]| 5 & 6 & |[draw=none]|7\\
 & |[draw=none]|8 &\\
};
\draw ($(gamea-3-1)!0.5!(gamea-4-2)$) ellipse [x radius=1.2cm, y radius=0.30cm,rotate=-45];
\draw ($(gamea-2-2)!0.5!(gamea-3-3)$) ellipse [x radius=1.2cm, y radius=0.30cm,rotate=-45];
\begin{scope}[on background layer]
\fill[black!20,rounded corners] ([xshift=-2mm]gamea-2-3.west) arc (180:0:5mm and 5mm) -- 
                    ([xshift=1mm]gamea-3-3.east) arc (0:-90:1cm and 1.5cm) arc 
                    (-90:-180:1cm and 0.8cm) |- ([shift={(3mm,2mm)}]gamea-3-2.north east) -- cycle;
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

最小方法贝阿特丽斯

\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\node (1) at (1,0) {1};
\foreach \x in {2,...,4}
{   \node (\x) at (\x-2,-1) {\x};
    \pgfmathtruncatemacro{\seli}{\x+3}
    \node (\seli) at (\x-2,-2) {\seli};
}
\node (8) at (1,-3) {8};
\fill[gray,rounded corners=2mm,even odd rule,opacity=0.25]  ($(3.north) + (0,0.2)$) -- ($(7.east) + (0.2,0)$) -- ($(8.south) + (0,-0.2)$) -- ($(5.west) + (-0.2,0)$) -- cycle (3.south) -- (7.west) -- (8.north) -- (5.east) -- cycle;

\draw (1) circle (0.2);
\draw (2) circle (0.2);
\draw (3) circle (0.2);
\draw (5) circle (0.2);

\draw (4.west) to[out=90,in=90,looseness=2] (4.east) -- (7.east) to [out=270,in=270,looseness=2] (7.west) -- cycle;
\draw (6.west) to[out=90,in=90,looseness=2] (6.east) -- (8.east) to [out=270,in=270,looseness=2] (8.west) -- cycle; 

\end{tikzpicture}

\end{document}

在此处输入图片描述


对于公共

\begin{tikzpicture}
\node (1) at (1,0) {1};
\foreach \x in {2,...,4}
{   \node (\x) at (\x-2,-1) {\x};
    \pgfmathtruncatemacro{\seli}{\x+3}
    \node (\seli) at (\x-2,-2) {\seli};
}
\node (8) at (1,-3) {8};

\fill[gray,rounded corners=1mm,opacity=0.25]  ($(2.north west)+(-0.1,0.1)$) -- ($(4.north east)+(0.1,0.1)$) -- ($(7.south east)+(0.1,-0.1)$) -- ($(8.south east)+(0.1,-0.1)$) -- ($(8.south west)+(-0.1,-0.1)$) -- ($(5.south west)+(-0.1,-0.1)$) -- cycle;

\draw (1) circle (0.2);
\draw (2) circle (0.2);

\draw[rounded corners=1mm] (5.north west) -- (6.north west) -- (3.north west) -- (4.north east) -- (7.south east) -- (8.south east) -- (8.south west) -- (5.south west) -- cycle;

\end{tikzpicture}

在此处输入图片描述

相关内容