tikz中曲线内的颜色区域

tikz中曲线内的颜色区域

我画了这幅画 在此处输入图片描述 使用以下代码

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

    \node (mth) [align=center] at (0,0) {parameter space of\\[2ex]{\Large M-Theory}};
    \node (so32) [align=center] at (-5,-1) {heterotic\\$SO(32)$};
    \node (e8e8) [align=center] at (-3,4) {heterotic\\$E(8) \times E(8)$};
    \node (tiia) [align=center] at (4,3) {Type II A};
    \node (tiib) [align=center] at (5,-2) {Type II B};
    \node (ti) [align=center] at (0,-5) {Type I};

    \draw[bend left,<->]  (so32) to node [below right,align=center] {compac-\\tification} (e8e8);
    \draw[bend left,<->]  (e8e8) to node [below left] {M-theory} (tiia);
    \draw[bend left,<->]  (tiia) to node [below left] {T-duality} (tiib);
    \draw[bend left,<->]  (tiib) to node [above left,align=center] {orientifold\\action $\Omega$} (ti);
    \draw[bend left,<->]  (ti) to node [above right] {S-duality} (so32);

    \draw[bend right,very thick]  (so32.east) to (e8e8.south);
    \draw[bend right,very thick]  (e8e8.south) to (tiia.south);
    \draw[bend right,very thick]  (tiia.south) to (tiib.west);
    \draw[bend right,very thick]  (tiib.west) to (ti.north);
    \draw[bend right,very thick]  (ti.north) to (so32.east);

\end{tikzpicture}
\end{document}

我想将粗黑线封闭的区域(即)涂成parameter space浅灰色。有人知道简单的方法吗?此外,我如何才能像这张图片一样在五个角上添加弯曲的灰线?

在此处输入图片描述

答案1

对于背景的颜色,您可以将其全部绘制为一条路径,然后填充。对于弯曲的灰线,您可以使用剪辑和圆圈,如下所示:

\documentclass[tikz]{standalone}

\begin{document}
\begin{tikzpicture}

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

\node (mth)  [align=center] at (0,0)   {parameter space of\\[2ex]{\Large M-Theory}};
\node (so32) [align=center] at (-5,-1) {heterotic\\$SO(32)$};
\node (e8e8) [align=center] at (-3,4)  {heterotic\\$E(8) \times E(8)$};
\node (tiia) [align=center] at (4,3)   {Type II A};
\node (tiib) [align=center] at (5,-2)  {Type II B};
\node (ti)   [align=center] at (0,-5)  {Type I};

\draw[bend left,<->]  (so32) to node [below right,align=center] {compac-\\tification} (e8e8);
\draw[bend left,<->]  (e8e8) to node [below left] {M-theory} (tiia);
\draw[bend left,<->]  (tiia) to node [below left] {T-duality} (tiib);
\draw[bend left,<->]  (tiib) to node [above left,align=center] {orientifold\\action $\Omega$} (ti);
\draw[bend left,<->]  (ti)   to node [above right] {S-duality} (so32);

\begin{pgfonlayer}{background}
  \draw[bend right,very thick, fill=lightgray]
    (so32.east)
      to (e8e8.south)
      to (tiia.south)
      to (tiib.west)
      to (ti.north)
      to (so32.east);

  \begin{scope}
    \clip[bend right]
      (so32.east)
        to (e8e8.south)
        to (tiia.south)
        to (tiib.west)
        to (ti.north)
        to (so32.east);
    \foreach \c in {so32.east,e8e8.south,tiia.south,tiib.west,ti.north,so32.east}{%
      \foreach \r in {1,...,4}{%
        \draw[darkgray] (\c) circle (\r*0.25cm);
      }
    }
  \end{scope}
\end{pgfonlayer}

\end{tikzpicture}
\end{document}

其结果是

输出

当然,您可以根据自己的喜好自定义填充和曲线的颜色。

答案2

对于第一部分,只需将内部路径构建为单个\draw命令而不破坏路径:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

    \node (so32) [align=center] at (-5,-1) {heterotic\\$SO(32)$};
    \node (e8e8) [align=center] at (-3,4) {heterotic\\$E(8) \times E(8)$};
    \node (tiia) [align=center] at (4,3) {Type II A};
    \node (tiib) [align=center] at (5,-2) {Type II B};
    \node (ti) [align=center] at (0,-5) {Type I};

    \draw[bend left,<->]  (so32) to node [below right,align=center] {compac-\\tification} (e8e8);
    \draw[bend left,<->]  (e8e8) to node [below left] {M-theory} (tiia);
    \draw[bend left,<->]  (tiia) to node [below left] {T-duality} (tiib);
    \draw[bend left,<->]  (tiib) to node [above left,align=center] {orientifold\\action $\Omega$} (ti);
    \draw[bend left,<->]  (ti) to node [above right] {S-duality} (so32);

    \draw[bend right,very thick,fill=black!20]
      (so32.east) to (e8e8.south)
       to (tiia.south)
       to (tiib.west)
       to (ti.north)
       to (so32.east)
      ;
    \node (mth) [align=center] at (0,0) {parameter space of\\[2ex]{\Large M-Theory}};

\end{tikzpicture}
\end{document}

我必须将mth节点移到填充区域下方,以便它显示在填充区域上方。如果您需要在此之前创建它,但仍将其放在前台,您可以使用

\pgfdeclarelayer{background}
\pgfsetlayers{background,main}

然后在背景中绘制填充的路径:

\begin{pgfonlayer}{background}
    \draw[bend right,very thick,fill=black!20]
      (so32.east) to (e8e8.south)
       to (tiia.south)
       to (tiib.west)
       to (ti.north)
       to (so32.east)
      ;
\end{pgfonlayer}

对于第二个问题,您可能会发现该angles库很有用,它记录在 PGF 最新版本手册的第 39 节中。

相关内容