如何控制“森林”盒子的高度

如何控制“森林”盒子的高度

我正在forest为一份报告绘制酶/底物的水平图。在我的实际standalone文件中,它目前的样子如下:

在此处输入图片描述

我想使用standalone以便可以添加引用和工作超链接。但是,包含文本的框太高,相对不重要的图形占用了主报告文档中的太多空间。我已经尝试过s sep等,但因为我认为这是个tikz问题(即文本框的高度),所以我不确定该怎么做,因为我最近才开始学习tikz。我绝对不知道如何forest与 交互tikz以设置node至少。

请问我怎样才能控制包含“马肝醇 DH”的框的高度node(例如)并减少单词上方和下方的空间?

我的 MWE 如下所示:

在此处输入图片描述

梅威瑟:

\documentclass[border=0mm]{standalone}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary{arrows,arrows.meta,automata,backgrounds,calc,
                  fit,shadings,shapes}
\usepackage{chemmacros}
\usepackage[hidelinks]{hyperref}

\begin{document}

\newcommand\hyperlinkStuff[2]{\scalebox{0.75}{\tiny(\color{blue}{\href{#1}{#2}}\color{black}{)}}}

\begin{forest}
    for tree={%
        grow'=east,
        edge={thick, -Stealth},
        tier/.option=level,
        if level=0{%
            thick,
            draw=none,
            font=\tiny,
            align=left,
            anchor=parent,
            l=-5mm,
            l sep=8mm,
            s sep=0mm,
            }{},
        if level=1{%
            thick,
            draw,
            font=\tiny,
            align=left,
            anchor=parent,
            s sep=0mm,
            }{},%
}
%
[\hspace{-2.08mm}Dehydrogen-\\\hspace{-2.08mm}ases (DH), for children={forked edge}, name=dh
    [\textit{A. fulgidus} \iupac{\L-Alanine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.1}{1.4.1.1}, name=afaladh]
    [Horse liver alcohol DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.1.1.1}{1.1.1.1}, name=hladh]
    [\iupac{\L-Amino} acid DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.5}{1.4.1.5}, name=aadh]
    [Glutamate DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.2}{1.4.1.2}, name=gdh    ]
    [\iupac{\L-Leucine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.9}{1.4.1.9}, name=leucine]
    [Amine DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.9.1}{1.4.9.1}, name=amdh]
]
%
\node[%above=2pt,
        font=\bfseries\tiny,
        above=4pt,
        anchor=west,
        ] at (afaladh.north west) {Enzyme name \scalebox{0.75}{\tiny(\normalfont EC number)}};
%
\end{forest}
\end{document}

答案1

您可以添加inner ysep=1pt(或任意长度)到for tree

在此处输入图片描述

\documentclass[border=0mm]{standalone}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary{arrows,arrows.meta,automata,backgrounds,calc,
                  fit,shadings,shapes}
\usepackage{chemmacros}
\usepackage[hidelinks]{hyperref}

\begin{document}

\newcommand\hyperlinkStuff[2]{\scalebox{0.75}{\tiny(\color{blue}{\href{#1}{#2}}\color{black}{)}}}

\begin{forest}
    for tree={%
        grow'=east,
        inner ysep=1pt,    % <----- Added
        edge={thick, -Stealth},
        tier/.option=level,
        if level=0{%
            thick,
            draw=none,
            font=\tiny,
            align=left,
            anchor=parent,
            l=-5mm,
            l sep=8mm,
            s sep=0mm,
            }{},
        if level=1{%
            thick,
            draw,
            font=\tiny,
            align=left,
            anchor=parent,
            s sep=0mm,
            }{},%
}
%
[\hspace{-2.08mm}Dehydrogen-\\\hspace{-2.08mm}ases (DH), for children={forked edge}, name=dh
    [\textit{A. fulgidus} \iupac{\L-Alanine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.1}{1.4.1.1}, name=afaladh]
    [Horse liver alcohol DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.1.1.1}{1.1.1.1}, name=hladh]
    [\iupac{\L-Amino} acid DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.5}{1.4.1.5}, name=aadh]
    [Glutamate DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.2}{1.4.1.2}, name=gdh    ]
    [\iupac{\L-Leucine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.9}{1.4.1.9}, name=leucine]
    [Amine DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.9.1}{1.4.9.1}, name=amdh]
]
%
\node[%above=2pt,
        font=\bfseries\tiny,
        above=4pt,
        anchor=west,
        ] at (afaladh.north west) {Enzyme name \scalebox{0.75}{\tiny(\normalfont EC number)}};
%
\end{forest}
\end{document}

答案2

我将编写提供的树代码如下:

\documentclass{standalone}

\usepackage{forest}
\useforestlibrary{edges}
\usetikzlibrary{arrows,arrows.meta,automata,backgrounds,calc,
                  fit,shadings,shapes}
\usepackage{chemmacros}
\usepackage[
    colorlinks=true,
    urlcolor=blue,
            ]{hyperref}  
\newcommand\hyperlinkStuff[2]{\scalebox{0.75}{\href{#1}{#2}}}

\begin{document}
    \begin{forest}
for tree={%
    font=\tiny,
    inner ysep =
    align=left,
    anchor=west,
%            
    grow'=east,
    edge={thick, -Stealth},
forked edge,        % for forked edge
    l sep = 6mm,
 fork sep = 2mm,   
    s sep = 1pt,    % <----
if level=1{draw, thick}{},
tier/.option=level,
            }
%
[Dehydrogen-\\ases (DH), name=dh
    [\textit{A. fulgidus} \iupac{\L-Alanine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.1}{1.4.1.1}, name=afaladh]
    [Horse liver alcohol DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.1.1.1}{1.1.1.1}, name=hladh]
    [\iupac{\L-Amino} acid DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.5}{1.4.1.5}, name=aadh]
    [Glutamate DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.2}{1.4.1.2}, name=gdh    ]
    [\iupac{\L-Leucine} DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.9}{1.4.1.9}, name=leucine]
    [Amine DH \hyperlinkStuff{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.9.1}{1.4.9.1}, name=amdh]
]
%
\node[font=\bfseries\tiny,
      above=4pt,
      anchor=west,
      ] at (afaladh.north west) {Enzyme name \scalebox{0.75}{(\normalfont EC number)}};
    \end{forest}
\end{document}

如您所见,节点之间的垂直距离由 设定s sep=1pt(在代码中用 标记<--)。您可以根据需要更改距离的大小。

在此处输入图片描述

编辑:
显然,由于某些未知的原因,您更喜欢节点的边界紧贴文本,并且节点具有垂直距离,例如如下所示:

在此处输入图片描述

对于这个(丑陋的)结果你需要for tree添加选项:

    inner ysep = 0.5pt, outer ysep=0pt,

并改为s sep = 1pt`s sep = 0pt。

附录:
对于第一幅有问题的图像,可能的解决方案是:

\documentclass{standalone}

\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\usepackage{chemmacros}
\usepackage[
    colorlinks=true,
    urlcolor=blue,
            ]{hyperref}
\newcommand\HLscale[2]{\scalebox{0.75}{\href{#1}{#2}}}

\begin{document}
    \begin{forest}
for tree={%
% nodes
    font=\tiny,
    inner sep=2pt, outer sep=0pt,
    align=left,
% tree
    grow'=east,
    anchor=west,
forked edge,        % for forked edge
    l sep = 6mm,
 fork sep = 3mm,
    s sep = 2pt,    % <----
/tikz/arr/.style = {thick, -{Stealth[scale=0.8]}},
if level  = 1{draw, thick}{},
if level> = 3{edge={draw=none}}{edge={arr}},
tier/.option=level,
            }
%
[Dehydrogen-\\ases (DH)
    [\textit{A. fulgidus} \iupac{\L-Alanine} DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.1}{1.4.1.1},
     name=m1
        [L-Alanine, name=n1
            [   [test name, name=t1]]]
    ]
    [Horse liver alcohol DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.1.1.1}{1.1.1.1}
        [Ethanol, name=n2
            [   [test name, name=t2]]]
    ]
    [\iupac{\L-Amino} acid DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.5}{1.4.1.5}
        [L-Glicine, name=n3
            [NADPH, name=nadph
                [test name, name=t3]
            ]
        ]
    ]
    [Glutamate DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.2}{1.4.1.2}
        [L-Glicine, name=n4
            [   [test name, name=t4]]
        ]
    ]
    [\iupac{\L-Leucine} DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.1.9}{1.4.1.9}
        [L-Leucine, name=n5
            [   [test name, name=t5]]
        ]
    ]
    [Amine DH
     \HLscale{https://www.brenda-enzymes.org/enzyme.php?ecno=1.4.9.1}{1.4.9.1},
        [Methylamine, name=n6
            [TTQ, name=ttq
                [Test, name=T]
            ]
        ]
    ]
]
%
\node[inner sep=2pt,
      font=\bfseries\tiny,
      above right,
      ] at (m1.north west) {Enzyme name \scalebox{0.75}{(\normalfont EC number)}};
\draw[thick]
        (nadph.west) -- ++ (-3mm,0) coordinate (aux-1) |- (n1)
        (aux-1)      |- (n2)
        (aux-1)      -- (n3)
        (aux-1)      |- (n4)
        (aux-1)      |- (n5)
%
        (nadph.east) -- ++ (3mm,0) coordinate (aux-2) |- (t1)
        (aux-2)      |- (t2)
        (aux-2)      -- (t3)
        (aux-2)      |- (t4)
        (aux-2)      |- (t5);
\draw[arr]  (n6) -- (ttq);
\draw[arr]  (ttq) -- (T);
    \end{forest}
\end{document}

在此处输入图片描述

相关内容