TikZ/pgf:使用“graphdrawing”库时,为什么即使定义了“component sep”,组件仍然重叠?

TikZ/pgf:使用“graphdrawing”库时,为什么即使定义了“component sep”,组件仍然重叠?

来源:

\documentclass{standalone}
\usepackage{fixltx2e}
\usepackage{amsmath}

\def\SP#1{\textsuperscript{#1}}
\def\SB#1{\textsubscript{#1}}
\def\SPSB#1#2{\rlap{\textsuperscript{#1}\textsubscript{#2}}}

%======================================
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{arrows}
\usetikzlibrary{graphs}
\usetikzlibrary{decorations.pathmorphing}
\usegdlibrary{force, layered, trees, ogdf}
%======================================

\begin{document}

            \tikz 
            \graph [spring layout, node distance = 20mm, nodes = draw, component sep = 5mm, component packing = rectangular]
            {

                RacOn/"\textbf{Rac\SB{on}}";
                kRacOnToOffM/"${k^{{Rac}}_{{on}\rightarrow{off}}}$";
                kRacOffMtoOn/"${k^{{Rac}}_{{on}\leftarrow{off}}}$";

                Rac [draw, circle] // [spring layout, node distance = 10mm, component sep = 5mm, component packing = rectangular]
                {   
                    RacOn ->[very thick, bend right, orient = 90]
                    kRacOffMtoOn ->[decorate, decoration=snake, blue, orient = 90]
                    RacOn ->[decorate, decoration=snake, red, orient = 90] 
                    kRacOnToOffM 
                };

                RhoOn/"\textbf{Rho\SB{on}}";
                kRhoOnToOffM/"${k^{{Rho}}_{{on}\rightarrow{off}}}$";
                kRhoOffMtoOn/"${k^{{Rho}}_{{on}\leftarrow{off}}}$";

                Rho [draw, circle] // [spring layout, node distance = 10mm, component sep = 5mm, component packing = rectangular]
                {   
                    kRhoOffMtoOn ->[decorate, decoration=snake, blue]
                    RhoOn ->[decorate, decoration=snake, red] 
                    kRhoOnToOffM 
                };

                chemoattractant/"chemoattractant";
                %chemoattractant -!- Rac;
                %chemoattractant -!- Rho;

                chemorepellant/"chemorepellant";
                %chemorepellant -!- Rac;
                %chemorepellant -!- Rho;

                memProtrusion/"membrane protrusion";
                %memProtrusion -!- Rac;
                %memProtrusion -!- Rho;

                memRetraction/"membrane retraction";
                %memRetraction -!- Rac;
                %memRetraction -!- Rho;

                memTension/"membrane tension";
                %memTension -!- Rac;
                %memTension -!- Rac;

                contact/"intercellular contact";
                %contact -!- Rac;
                %contact -!- Rho;

                chemoattractant ->[very thick] kRacOffMtoOn; 
                chemorepellant ->[very thick] kRhoOffMtoOn;

                RacOn ->[very thick, bend right] memProtrusion ->[very thick] memTension ->[very thick] kRacOnToOffM;

                RhoOn ->[very thick] memRetraction ->[>=|, very thick] memTension;

                contact ->[very thick, bend right] kRhoOffMtoOn;


            };

\end{document}

输出:

在此处输入图片描述

问题:

我打开了所有节点的边框绘制,如上所示,您可以看到,即使在我指定了键之后,它们中的很多仍然重叠component sep

我猜测正在发生的事情是,由于某种原因,在进行这些计算时没有考虑每个节点的“文本”。

为了实现适当的分离我应该怎么做?

答案1

这是另一个建议layered layout

\documentclass[tikz,margin=5mm]{standalone}
\usepackage{fixltx2e}
\usepackage{amsmath}
\def\SP#1{\textsuperscript{#1}}
\def\SB#1{\textsubscript{#1}}
\def\SPSB#1#2{\rlap{\textsuperscript{#1}\textsubscript{#2}}}

\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,arrows}
\usetikzlibrary{decorations.pathmorphing}
\usegdlibrary{force, layered, trees}

\begin{document}
\tikz\graph [layered layout, nodes=draw]
  {
    RacOn/"\textbf{Rac\SB{on}}";
    kRacOnToOffM/"${k^{{Rac}}_{{on}\rightarrow{off}}}$";
    kRacOffMtoOn/"${k^{{Rac}}_{{on}\leftarrow{off}}}$";
%
    Rac [draw, circle]//[spring layout]
      {
        RacOn ->[very thick, bend right, orient = 90]
        kRacOffMtoOn ->[decorate, decoration=snake, blue, orient = 90]
        RacOn ->[decorate, decoration=snake, red, orient = 90] 
        kRacOnToOffM 
      };
%
    RhoOn/"\textbf{Rho\SB{on}}";
    kRhoOnToOffM/"${k^{{Rho}}_{{on}\rightarrow{off}}}$";
    kRhoOffMtoOn/"${k^{{Rho}}_{{on}\leftarrow{off}}}$";
%
    Rho [draw, circle]//[spring layout]
      {
        kRhoOffMtoOn ->[decorate, decoration=snake, blue]
        RhoOn ->[decorate, decoration=snake, red] 
        kRhoOnToOffM 
      };
%
    chemorepellant ->[very thick,bend right=30] kRhoOffMtoOn;
    chemoattractant ->[very thick] kRacOffMtoOn;
    contact ->[very thick, bend right] kRhoOffMtoOn;
    RhoOn ->[very thick,bend right=70] memRetraction/"membrane retraction"
      ->[>=|, very thick, bend right=10] memTension/"membrane tension";
    RacOn ->[very thick, bend right=90] memProtrusion/"membrane protrusion" 
      ->[very thick] memTension ->[very thick,bend right=65] kRacOnToOffM;
  };
\end{document}

在此处输入图片描述

答案2

增加作品的价值node distance

\documentclass{standalone}
\usepackage{fixltx2e}
\usepackage{amsmath}

\def\SP#1{\textsuperscript{#1}}
\def\SB#1{\textsubscript{#1}}
\def\SPSB#1#2{\rlap{\textsuperscript{#1}\textsubscript{#2}}}

%======================================
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{arrows}
\usetikzlibrary{graphs}
\usetikzlibrary{decorations.pathmorphing}
\usegdlibrary{force, layered, trees}
%======================================

\begin{document}

            \tikz 
            \graph [spring layout, node distance= 5.5cm, nodes = draw, component sep = 50mm, component packing = rectangular]
            {

                RacOn/"\textbf{Rac\SB{on}}";
                kRacOnToOffM/"${k^{{Rac}}_{{on}\rightarrow{off}}}$";
                kRacOffMtoOn/"${k^{{Rac}}_{{on}\leftarrow{off}}}$";

                Rac [draw, circle] // [spring layout, node distance = 10mm, component sep = 5mm, component packing = rectangular]
                {   
                    RacOn ->[very thick, bend right, orient = 90]
                    kRacOffMtoOn ->[decorate, decoration=snake, blue, orient = 90]
                    RacOn ->[decorate, decoration=snake, red, orient = 90] 
                    kRacOnToOffM 
                };

                RhoOn/"\textbf{Rho\SB{on}}";
                kRhoOnToOffM/"${k^{{Rho}}_{{on}\rightarrow{off}}}$";
                kRhoOffMtoOn/"${k^{{Rho}}_{{on}\leftarrow{off}}}$";

                Rho [draw, circle] // [spring layout, node distance = 10mm, component sep = 5mm, component packing = rectangular]
                {   
                    kRhoOffMtoOn ->[decorate, decoration=snake, blue]
                    RhoOn ->[decorate, decoration=snake, red] 
                    kRhoOnToOffM 
                };

                chemoattractant/"chemoattractant";
                %chemoattractant -!- Rac;
                %chemoattractant -!- Rho;

                chemorepellant/"chemorepellant";
                %chemorepellant -!- Rac;
                %chemorepellant -!- Rho;

                memProtrusion/"membrane protrusion";
                %memProtrusion -!- Rac;
                %memProtrusion -!- Rho;

                memRetraction/"membrane retraction";
                %memRetraction -!- Rac;
                %memRetraction -!- Rho;

                memTension/"membrane tension";
                %memTension -!- Rac;
                %memTension -!- Rac;

                contact/"intercellular contact";
                %contact -!- Rac;
                %contact -!- Rho;

                chemoattractant ->[very thick] kRacOffMtoOn; 
                chemorepellant ->[very thick] kRhoOffMtoOn;

                RacOn ->[very thick, bend right] memProtrusion ->[very thick] memTension ->[very thick] kRacOnToOffM;

                RhoOn ->[very thick] memRetraction ->[>=|, very thick] memTension;

                contact ->[very thick, bend right] kRhoOffMtoOn;


            };

\end{document}

在此处输入图片描述

node distance在图书馆的情况下有一个特殊的行为graphdrawing,如第节所述27.3 填充和节点距离PGF 手册:

这是由一条边连接的节点中心应具有的最小距离。并不总是能够满足这个期望距离,例如当节点太大时。在这种情况下,长度仅被视为下限。

因此,如果节点太大(如您相对于最初指定的值的情况一样),则距离将被视为下限。

node distance对于这个库来说,它似乎有点奇怪(至少对我来说)graphdrawing;例如,有些布局会默默地忽略这个选项。

相关内容