在 tikz 中用曲线紧紧围绕列表节点

在 tikz 中用曲线紧紧围绕列表节点

我有以下 MWE:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,calc,positioning,matrix,fit}
\usepackage{enumitem}

\begin{document}
    \begin{tikzpicture}
            \node (B) {
                \parbox{0.5\hsize}{
                    \textit{\underline{Margherita:}}
                    \begin{itemize}
                        \item {tomatoes}
                        \item {mozzaerlla}
                        \item {cheese}
                    \end{itemize}
                }
            };
            \node (C) at ($(B.east)+(1.1,0)$) {
                \parbox{0.5\hsize}{
                    \textit{\underline{Pepperoni}}
                    \begin{itemize}
                        \item {pepper}
                        \item[] {}
                        \item[] {}
                    \end{itemize}
                }
            };
            \coordinate (M) at ($0.5*(B.north east)+0.5*(C.north west)$);
            \node (A) at ($(M.north)+(-1.7,0.6)$) {Pizza varieties};
            \coordinate (b1) at (B.north west);
            \coordinate (b2) at (B.north east);
            \coordinate (b3) at (B.south east);
            \coordinate (b4) at (B.south west);
            \path[draw=black] (b1) to[bend left=45] (b2)
                                   to[bend left=45] (b3) 
                                   to[bend left=45] (b4)
                                   -- cycle;
    \end{tikzpicture}
\end{document}

从代码可以看出,我想绘制一条曲线,紧紧围绕节点中包含的列表B。我还想对C整个图像执行相同的操作(即,节点A应该位于“层次结构中”,尽管在代码中并非如此)。但是,当将锚定在列表节点周围时,它会围绕整个节点。如何紧密拟合曲线?

smooth cycle'' rather than编辑:可以通过在外面设置“平滑”然后“循环”来改进下面的答案(参见这个 SE 问题)。

答案1

您的节点太宽了\parbox{0.5\hsize}{...}。请缩短它的宽度。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{enumitem}

\begin{document}
\begin{tikzpicture}[rs/.style={align=left,text width=7.5em}]
   \node[rs] (B) {\textit{\underline{Margherita:}}
           \begin{itemize}
               \item {tomatoes}
               \item {mozzaerlla}
               \item {cheese}
           \end{itemize}
   };
   \node[right=1cm of B,rs] (C){
           \textit{\underline{Pepperoni}}
           \begin{itemize}
               \item {pepper}
               \item[] {}
               \item[] {}
           \end{itemize}
   };
   \path (B.north east) -- (C.north west) 
   node[midway,above=1cm,xshift=-1.7cm] (A) {Pizza varieties};
   \path[draw=black] (B.north west)  to[bend left=45] (B.north east)
                          to[bend left=45] (B.south east)
                          to[bend left=45] (B.south west)
                          -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

在这个例子中,圆弧bend left看起来不错,但一般来说,它们不会产生平滑的轮廓。然后你可以做类似的事情

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{enumitem}

\begin{document}
\begin{tikzpicture}[rs/.style={align=left,text width=7.5em}]
   \node[rs] (B) {\textit{\underline{Margherita:}}
           \begin{itemize}
               \item {tomatoes}
               \item {mozzaerlla}
               \item {cheese}
           \end{itemize}
   };
   \node[right=1cm of B,rs] (C){
           \textit{\underline{Pepperoni}}
           \begin{itemize}
               \item {pepper}
               \item[] {}
               \item[] {}
           \end{itemize}
   };
   \path (B.north east) -- (C.north west) 
   node[midway,above=1cm,xshift=-1.7cm] (A) {Pizza varieties};
   \path[draw=black]
    plot[smooth,tension=1] coordinates {(B.north west)  (B.north east)
    (B.south east) (B.south west)}
                          -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容