在 Tikz 中在形狀之間繪製

在 Tikz 中在形狀之間繪製

我正在嘗試從中心圓(大會)到經濟及社會理事會和國際刑事法院圓畫線,使得所有三個圓上的線的入射角都是 0 度,即該線位於與圓表面成90 度角。現在,這就是我所擁有的。

\documentclass{article}
\usetikzlibrary{calc}
\usetikzlibrary{matrix, shapes}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{snakes}
\usetikzlibrary{positioning, intersections}
\pgfplotsset{compat=1.10}
\begin{document}

    \begin{figure}[H]
    \label{fig:structure}
    \centering
    \begin{tikzpicture}
    \node[xshift=6cm,draw,regular polygon, regular polygon sides=4,text width=3cm,align=center] (sa)
      {{\Large Specialized agencies}:\\
      \textbullet FAO\\
      \textbullet ILO\\
      \textbullet ITU\\
      \textbullet WHO};
      \node[minimum size= 4.5cm, xshift=12cm,draw,circle, text width=3cm,align=center] (ga) {\Large{General Assembly}\\
      \small{1 nation, 1 vote}};
      \node[xshift=12cm,yshift=-5cm,draw, circle, text width=3cm,align=center] (sc) {\Large Security Council\\
      \small{5 permanent members\\
      10 rotating members chosen by GA}};
        \node[xshift=12cm,yshift=5cm,draw,circle, text width=3cm,align=center] (sg) {\Large Secretary General\\
      \small{Supports GA decisions}};
          \node[xshift=17cm,yshift=2cm,draw,circle, text width=3cm,align=center] (ecsoc) {\Large Economic and Social Council
    };
          \node[xshift=17cm,yshift=-2cm,draw,circle, text width=3cm,align=center] (icc) {\Large International Criminal Court
    };
    \draw (sa.east) -- (ga.west);
    \draw (sg.south) -- (ga.north);
    \draw (sc.north) -- (ga.south);
    \draw (ga.east) -- (ecsoc.west);
    \draw (ga.east) -- (icc.west);
    \end{tikzpicture}
    \caption{Structure of the United Nations}
    \end{figure}

\end{document}

圖表

答案1

如果您的意思是它們必須垂直於圓邊界,則不要--使用 ,edge[out=0, in=180]而是使用 in \draw (ga.east) edge[out=0, in=180] (ecsoc.west);。這樣,線以 0 度(右)退出,以 180 度(左)進入。

另外,將 Tikz 庫全部寫在一個地方,用逗號分隔,您呼叫 Tikz 包,這樣它就不會產生錯誤。我通常會列出我需要的所有包,然後在所有可用的情況下列出庫。這樣它也更容易理解並且更有組織性。

圖1

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{positioning, intersections, calc, matrix, shapes, snakes}
\pgfplotsset{compat=1.10}

\begin{document}

    \begin{figure}[H]
    \label{fig:structure}
    \centering
    \begin{tikzpicture}
    \node[xshift=6cm,draw,regular polygon, regular polygon sides=4,text width=3cm,align=center] (sa)
      {{\Large Specialized agencies}:\\
      \textbullet FAO\\
      \textbullet ILO\\
      \textbullet ITU\\
      \textbullet WHO};
      \node[minimum size= 4.5cm, xshift=12cm,draw,circle, text width=3cm,align=center] (ga) {\Large{General Assembly}\\
      \small{1 nation, 1 vote}};
      \node[xshift=12cm,yshift=-5cm,draw, circle, text width=3cm,align=center] (sc) {\Large Security Council\\
      \small{5 permanent members\\
      10 rotating members chosen by GA}};
        \node[xshift=12cm,yshift=5cm,draw,circle, text width=3cm,align=center] (sg) {\Large Secretary General\\
      \small{Supports GA decisions}};
          \node[xshift=17cm,yshift=2cm,draw,circle, text width=3cm,align=center] (ecsoc) {\Large Economic and Social Council
    };
          \node[xshift=17cm,yshift=-2cm,draw,circle, text width=3cm,align=center] (icc) {\Large International Criminal Court
    };
    \draw (sa.east) -- (ga.west);
    \draw (sg.south) -- (ga.north);
    \draw (sc.north) -- (ga.south);
    \draw (ga.east) edge[out=0, in=180] (ecsoc.west);
    \draw (ga.east) edge[out=0, in=180] (icc.west);
    \end{tikzpicture}
    \caption{Structure of the United Nations}
    \end{figure}

\end{document}

順便說一句,您可以透過添加關鍵「鬆散度」來修改曲線外觀。預設值為 1,0 建立直線,增加數字會突出曲線。這是一個例子(黑色的是標準的,或1):

圖2

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{positioning, intersections, calc, matrix, shapes, snakes}
\pgfplotsset{compat=1.10}

\begin{document}

    \begin{tikzpicture}
    \node[draw, circle, text width=3cm, align=center] (ga) {\Large General Assembly};
    \node[draw, circle, text width=3cm, align=center, xshift=6cm, yshift=3cm] (ecsoc) {\Large Economic and Social Council};

    \draw[green] (ga.east) edge[out=0, in=180, looseness=0] (ecsoc.west);
    \draw (ga.east) edge[out=0, in=180, looseness=1] (ecsoc.west);
    \draw[red] (ga.east) edge[out=0, in=180, looseness=5] (ecsoc.west);
    \draw[blue] (ga.east) edge[out=0, in=180, looseness=10] (ecsoc.west);

    \end{tikzpicture}

\end{document}

相關內容