边界框如何工作?

边界框如何工作?

我想将直方图包含在第一个和第二个节点中,并带有边界框,其余节点仅包含文本。 这是我的工作:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning,calc,fit}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{tikzpicture}

            \begin{axis}[
                ybar=-0.10cm,
                axis x line*=bottom,
                axis y line*=left,
                height=3.5cm, width=3.4cm,
                bar width=0.1cm,
                symbolic x coords={topic1,topic2,topic3},
                %xtick={topic1,topic2,topic3},
                label style={font=\tiny},
                tick label style={font=\tiny}]
                \addplot[BlueGreen,fill] coordinates {(topic1,0.4)};
                \addplot[Cyan,fill] coordinates {(topic2,0.5)};
                \addplot[ForestGreen,fill] coordinates {(topic3,0.1)};
                
            \end{axis}
        (bounding box)
        \node[draw=red, fit=(current bounding box)](a){};
        \node[right = 4cm of a, draw=red,] (b) {sometext};
        \node[right = 4cm of b, draw=red,] (c) {sometext};


        
        \draw[->] ($(a.north east)!0.25!(a.south east)$) -- node[below] {arrow text} ($(b.north west)!0.25!(b.south west)$);
        \draw[->] ($(b.north east)!0.25!(b.south east)$) -- node[below] {arrow text} ($(c.north west)!0.25!(c.south west)$);
        %\draw(a.east)--++(2,0);



    % more arrows here
\end{tikzpicture}
%   \newpage
\end{document}
  1. 我不知道如何将边界框再次适配到第二个节点,以及边界框如何工作?

  2. 如何固定节点大小?

在此处输入图片描述

答案1

  • 将节点的复杂内容(如tikzpicture带有环境的 s )保存axis在一个框中,并在另一个 中使用这些框tikzpicture。使用 LaTeX 命令\newsavebox\savebox\usebox;参见例如这里了解描述。

  • 您可以设置节点的最小高度和宽度,这样如果节点内部没有太多文本,它们就不会折叠。原则上,也可以让 LaTeX 测量图表的大小并将其用作最小高度和宽度,但对于一次性绘图来说,这可能有点过头了。

在此处输入图片描述

\documentclass[border=4pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\newsavebox\A
\savebox\A{%
  \begin{tikzpicture}
    \begin{axis}[
      ybar=-0.10cm,
      axis x line*=bottom,
      axis y line*=left,
      height=3.5cm, width=3.4cm,
      bar width=0.1cm,
      symbolic x coords={topic1,topic2,topic3},
      %xtick={topic1,topic2,topic3},
      label style={font=\tiny}, tick label
      style={font=\tiny}]
      \addplot[BlueGreen,fill] coordinates {(topic1,0.4)};
      \addplot[Cyan,fill] coordinates {(topic2,0.5)};
      \addplot[ForestGreen,fill] coordinates {(topic3,0.1)};
    \end{axis}
  \end{tikzpicture}%
}
\begin{tikzpicture}[
  mynode/.style={draw=red,minimum height=3cm,minimum width=2cm}
  ]
  \node[mynode](a){\usebox\A};
  \node[mynode,right = 4cm of a] (b) {\usebox\A};
  \node[mynode,right = 4cm of b,align=center] (c) {some\\lines\\of\\text};
  \draw[->] (a) -- node[below] {arrow text} (b);
  \draw[->] (b) -- node[below] {arrow text} (c);
\end{tikzpicture}
\end{document}

相关内容