缩放具有阴影节点的节点的 TikZ 矩阵

缩放具有阴影节点的节点的 TikZ 矩阵

我尝试使用 TikZmatrix of nodes重建先前创建的图像。目标如下:

Target image

对此我有两个一般性问题:1) 有没有更“TikZy”的方式来创建插图中具有相应大小并跨越多行的矩形?2) 如何缩放整个图像,使其适合纵向 A4 纸(下图是在横向 A3 纸上创建的)?

我到目前为止所做的(代码和当前结果图像附在下面):

为了创建“Job Builder”、“GNU Parallel”和“Computing Cluster”形状,我创建了节点并将相应的矩形拟合到其中。如果我现在使用所述缩放比例这里(添加[scale=0.6, every node/.style={scale=0.6}]到 tikzpicture),阴影节点作为拟合点变得可见(最后一张图)。此外,节点之间的关系变得很奇怪。有没有办法缩放整个插图,因为可以使用语句来做到这一点\includegraphics[width=\textwidth]{...}

\documentclass{scrartcl}
\usepackage{lscape}
\usepackage{tikz}
\usetikzlibrary{backgrounds,matrix,fit}
\tikzset{
    >=latex,
    every path/.style={thick},
    grey_vertex/.style={rectangle, draw, thick, top color=white, bottom color=black!20, draw=black!50, align=center, minimum size = 10pt},
    edge_label/.style={auto, font={\tiny\itshape}},
    vertex_bg_good/.style={rectangle,thick,bottom color=green!20,top color=green!10}
}

\begin{document}
    \begin{figure}
        \begin{tikzpicture}
            \matrix(m)[row sep=5mm, column sep=15mm, matrix of nodes, nodes={grey_vertex, circle, text width=4.7em}, font=\footnotesize]
            {
                {Parameters\\EA 1}  &                 & {Config\\EA 1}  &            & {EA\\Template}    & {Input\\Files}    & \node(mRes1){Results\\EA 1}; & \node(mSta1){Statistics\\EA 1};   \\
                {Parameters\\EA 2}  & \node(m22){};   & {Config\\EA 2}  &            &                   &                   & \node(mRes2){Results\\EA 2}; & \node(mSta2){Statistics\\EA 2};   \\
                                    &                 &                 & {jobs.sh}  & \node(mPar1){};   & \node(mPar2){};   &                              &                                   \\
                {...}               & \node(m42){};   & {...}           &            &                   &                   & \node(mResx){...};           & \node(mStax){...};                \\
                {Parameters\\EA n}  &                 & {Config\\EA n}  &            & \node(mclu1){};   & \node(mclu2){};   & \node(mResn){Results\\EA n}; & \node(mStan){Statistics\\EA n};   \\
            };
            \node[grey_vertex, rectangle, rounded corners, fit=(m22)(m42)]       (BG1)   {Job\\Builder};
            \node[grey_vertex, rectangle, rounded corners, fit=(mPar1)(mPar2)]   (BG2)   {GNU\\Parallel};
            \node[grey_vertex, rectangle, rounded corners, fit=(mclu1)(mclu2)]   (BG3)   {Computing\\Cluster};
            \begin{scope}[on background layer]
                \node[vertex_bg_good,draw,fit=(mRes1)(mSta1)] (mFRes1) {};
                \node[vertex_bg_good,draw,fit=(mRes2)(mSta2)] (mFRes2) {};
                \node[vertex_bg_good,draw,fit=(mResx)(mStax)] (mFResx) {};
                \node[vertex_bg_good,draw,fit=(mResn)(mStan)] (mFResn) {};
            \end{scope}
            \draw[->] (m-1-1) -- (BG1);
            \draw[->] (m-2-1) -- (BG1);
            \draw[->] (m-4-1) -- (BG1);
            \draw[->] (m-5-1) -- (BG1);
            \draw[->] (BG1) -- (m-1-3);
            \draw[->] (BG1) -- (m-2-3);
            \draw[->] (BG1) -- (m-4-3);
            \draw[->] (BG1) -- (m-5-3);
            \draw[->] (m-1-3) -- (m-3-4);
            \draw[->] (m-2-3) -- (m-3-4);
            \draw[->] (m-4-3) -- (m-3-4);
            \draw[->] (m-5-3) -- (m-3-4);
            \draw[->] (m-3-4) -- (BG2);
            \draw[->] (m-1-5) -- (BG2);
            \draw[->] (m-1-6) -- (BG2);
            \draw[->] (BG2) edge[bend left=30] (BG3);
            \draw[->] (BG3) edge[bend left=30] (BG2);
            \draw[->] (BG2.east) -- (mFRes1.south west);
            \draw[->] (BG2.east) -- (mFRes2.south west);
            \draw[->] (BG2.east) -- (mFResx.north west);
            \draw[->] (BG2.east) -- (mFResn.north west);
        \end{tikzpicture}
    \end{figure}
\end{document}

Current result without scaling 当前结果在 A3 纸和横向上未经缩放。

Current result with scaling 当前结果在 A4 纸和纵向上缩放。

答案1

为了避免层(和其他层)重新缩放的复杂性,您可以使用\resizebox,除非tikzpicture内容&是由于基质材料。在这种情况下,必须将&中的 更改为其他内容 :例如\&按照手册的建议并添加选项 :ampersand replacement=\&

enter image description here

\documentclass{scrartcl}
\usepackage{lscape,graphicx}
\usepackage{tikz}
\usetikzlibrary{backgrounds,matrix,fit}
\tikzset{
    >=latex,
    every path/.style={thick},
    grey_vertex/.style={rectangle, draw, thick, top color=white, bottom color=black!20, draw=black!50, align=center, minimum size = 10pt},
    edge_label/.style={auto, font={\tiny\itshape}},
    vertex_bg_good/.style={rectangle,thick,bottom color=green!20,top color=green!10}
}

\begin{document}
    \begin{figure}
   \resizebox{\linewidth}{!}{%
        \begin{tikzpicture}[ampersand replacement=\&]
            \matrix(m)[row sep=5mm, column sep=15mm, matrix of nodes, nodes={grey_vertex, circle, text width=4.7em}, font=\footnotesize]
            {
                {Parameters\\EA 1}   \&                  \& {Config\\EA 1}   \&             \& {EA\\Template}     \& {Input\\Files}     \& \node(mRes1){Results\\EA 1};  \& \node(mSta1){Statistics\\EA 1};   \\
                {Parameters\\EA 2}   \& \node(m22){};    \& {Config\\EA 2}   \&             \&                    \&                    \& \node(mRes2){Results\\EA 2};  \& \node(mSta2){Statistics\\EA 2};   \\
                                     \&                  \&                  \& {jobs.sh}   \& \node(mPar1){};    \& \node(mPar2){};    \&                               \&                                   \\
                {...}                \& \node(m42){};    \& {...}            \&             \&                    \&                    \& \node(mResx){...};            \& \node(mStax){...};                \\
                {Parameters\\EA n}   \&                  \& {Config\\EA n}   \&             \& \node(mclu1){};    \& \node(mclu2){};    \& \node(mResn){Results\\EA n};  \& \node(mStan){Statistics\\EA n};   \\
            };
           \node[grey_vertex, rectangle, rounded corners, fit=(m22)(m42)]       (BG1)   {Job\\Builder};
            \node[grey_vertex, rectangle, rounded corners, fit=(mPar1)(mPar2)]   (BG2)   {GNU\\Parallel};
            \node[grey_vertex, rectangle, rounded corners, fit=(mclu1)(mclu2)]   (BG3)   {Computing\\Cluster};
            \begin{scope}[on background layer]
                \node[vertex_bg_good,draw,fit=(mRes1)(mSta1)] (mFRes1) {};
                \node[vertex_bg_good,draw,fit=(mRes2)(mSta2)] (mFRes2) {};
                \node[vertex_bg_good,draw,fit=(mResx)(mStax)] (mFResx) {};
                \node[vertex_bg_good,draw,fit=(mResn)(mStan)] (mFResn) {};
            \end{scope}
            \draw[->] (m-1-1) -- (BG1);
            \draw[->] (m-2-1) -- (BG1);
            \draw[->] (m-4-1) -- (BG1);
            \draw[->] (m-5-1) -- (BG1);
            \draw[->] (BG1) -- (m-1-3);
            \draw[->] (BG1) -- (m-2-3);
            \draw[->] (BG1) -- (m-4-3);
            \draw[->] (BG1) -- (m-5-3);
            \draw[->] (m-1-3) -- (m-3-4);
            \draw[->] (m-2-3) -- (m-3-4);
            \draw[->] (m-4-3) -- (m-3-4);
            \draw[->] (m-5-3) -- (m-3-4);
            \draw[->] (m-3-4) -- (BG2);
            \draw[->] (m-1-5) -- (BG2);
            \draw[->] (m-1-6) -- (BG2);
            \draw[->] (BG2) edge[bend left=30] (BG3);
            \draw[->] (BG3) edge[bend left=30] (BG2);
            \draw[->] (BG2.east) -- (mFRes1.south west);
            \draw[->] (BG2.east) -- (mFRes2.south west);
            \draw[->] (BG2.east) -- (mFResx.north west);
            \draw[->] (BG2.east) -- (mFResn.north west);
        \end{tikzpicture}}
    \end{figure}
\end{document}

相关内容