tikz 在范围的“fit”和相对定位之间的相互作用

tikz 在范围的“fit”和相对定位之间的相互作用

fit包和范围的相对定位之间似乎存在奇怪的交互tikz,就像我不明白为什么事情会这样发生。这是我的代码:

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand\acr[1]{#1}

\usetikzlibrary{fit,positioning,calc}
\begin{document}
\tikzset{anacat/.style={anchor=north west,minimum height=1.5em,x=.3cm,y=.25cm,every node/.style={scale=0.3}}}
\tikzset{bin/.style={draw=black,anchor=west,text width=3cm}}
  \begin{tikzpicture}[x=1cm,y=1.5cm]
  \begin{scope}[shift={(0,0)},local bounding box=Hyy,anacat]
    \node[rotate=90,anchor=north,align=center] at (0,3) {$H\to\gamma\gamma$};
    \node[bin] at (1,0) {low $p_{\textrm{T}t}$};
    \node[bin] at (1,1) {high $p_{\textrm{T}t}$};
    \node[bin] at (1,2) {\acr{VBF} loose (\acr{MVA})};
    \node[bin] at (1,3) {\acr{VBF} tight (\acr{MVA})};
    \node[bin] at (1,4) {\acr{VH} leptonic};
    \node[bin] at (1,5) {$VH$ leptonic};
    \node[bin] at (1,6) {$t\bar{t}H$ leptonic};  
  \end{scope}
  \node[draw,dotted,fit=(Hyy)] (Hyybox) {};
  %      \begin{scope}[shift={(0,-1)},local bounding box=HZZ,anacat]
  \begin{scope}[shift={(Hyy.south west)},local bounding box=HZZ,anacat]
    \node[rotate=90,anchor=north,align=center] at (0,2) {$H\to ZZ$};
    \node[bin] at (1,0) {ggF $n_{j}=0$};
    \node[bin] at (1,1) {ggF $n_{j}=1$};
    \node[bin] at (1,2) {\acr{VBF} leptonic};
    \node[bin] at (1,3) {\acr{VH} leptonic};
    \node[bin] at (1,4) {\acr{VH} hadronic};
  \end{scope}
  \node[draw,dotted,fit=(HZZ)] {};
  %      \begin{scope}[shift={(0,-2.15)},local bounding box=HWW,anacat]
  \begin{scope}[shift={(HZZ.south west)},local bounding box=HWW,anacat]
    \node[rotate=90,anchor=north,align=center] at (0,2.5) {$H\to WW$};
    \node[bin] at (1,0) {ggF $n_{j}=0$};
    \node[bin] at (1,1) {ggF $n_{j}=1$};
    \node[bin] at (1,2) {ggF $n_{j}\geq 2$};
    \node[bin] at (1,3) {\acr{VBF} $n_{j}\geq 2$};
    \node[bin] at (1,4) {\acr{WH}};
    \node[bin] at (1,5) {\acr{ZH}};
  \end{scope}
  \node[draw,dotted,fit=(HWW)] {};
  %      \begin{scope}[shift={(0,-3))},local bounding box=Hbb,anacat]
  \begin{scope}[shift={(HWW.south west)},local bounding box=Hbb,anacat]
    \node[rotate=90,anchor=north,align=center] at (0,2) {$H\to b\bar{b}$};
    \node[bin] at (1,1) {\acr{MVA} low $p_{\textrm{T}^V}$};
    \node[bin] at (1,2) {\acr{MVA} low $p_{\textrm{T}^V}$};
    \node[bin] at (1,3) {$\cdots$};
  \end{scope}
  \node[draw,dotted,fit=(Hbb)] {};
  %      \begin{scope}[shift={(0,-3.45)},local bounding box=Htt,anacat]
  \begin{scope}[shift={(Hbb.south west)},local bounding box=Htt,anacat]
    \node[rotate=90,anchor=north,align=center] at (0,1) {$H\to \tau\bar{\tau}$};
    \node[bin] at (1,1) {$\cdots$};
  \end{scope}
  \node[draw,dotted,fit=(Htt)] {};
\end{tikzpicture}

\end{document}

这是我期望它看起来的样子(这些是注释掉的行):

好的

它的实际样子如下:

坏的

PS:这是这个

答案1

如果将节点相对放置,会容易一些。例如,这是示例的更简化版本。可以使用此处较低范围使用的相同模式来完成图表的其余部分。

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\newcommand\acr[1]{#1}
\usetikzlibrary{fit,positioning}
\begin{document}
\tikzset{%
  anacat/.style={minimum height=1.5em,x=.3cm,y=.25cm,every node/.style={scale=0.3}},
  bin/.style={draw=black,anchor=west,text width=3cm},
}%
\begin{tikzpicture}[x=1cm,y=1.5cm]
  \begin{scope}[local bounding box=Hyy,anacat]
    \node (p-0) [bin] at (1,0) {low $p_{\textrm{T}t}$};
    \foreach \i [count=\j, remember=\j as \jlast (initially 0)] in {{high $p_{\textrm{T}t}$},{\acr{VBF} loose (\acr{MVA})},{\acr{VBF} tight (\acr{MVA})},{\acr{VH} leptonic},{$VH$ leptonic},{$t\bar{t}H$ leptonic}}
    \node (p-\j) [below=2.5mm of p-\jlast.west, bin] {\i} ;
  \end{scope}
  \node (p-l) [rotate=90,anchor=south,align=center,yshift=.5mm, scale=.3] at (Hyy.west) {$H\to\gamma\gamma$};
  \node[draw,dotted,fit=(Hyy) (p-l)] (Hyybox) {};
  \begin{scope}[shift=(Hyy.south -| p-0.west),local bounding box=HZZ,anacat]
    %     ;
    \node (q-0) [below=5mm of p-6.west, bin] {ggF $n_{j}=0$};
    \foreach \i [count=\j, remember=\j as \jlast (initially 0)] in {{ggF $n_{j}=1$},{\acr{VBF} leptonic},{\acr{VH} leptonic},{\acr{VH} hadronic}}
    \node (q-\j) [below=2.5mm of q-\jlast.west, bin] {\i} ;
    \node (q-l) [rotate=90,anchor=center,align=center] at (p-l |- HZZ.west) {$H\to ZZ$};
  \end{scope}
  \node [draw,dotted,fit=(HZZ)] {};
\end{tikzpicture}
\end{document}

上限和下限

您也可以使用该chains库,尽管它已被弃用。(等效方法涉及使用图形语法,但使用起来不那么简单。)但是,该库有错误,由于其状态,无法修复。尽管如此,还是chains可以通过抽象循环来简化此处的代码。

或者,您可以将图表视为一棵永不分支的树。那么库trees、内置树语法或更专业的包之一(例如 Forest 或tikz-qtree)将是选项。

相关内容