tikzpicture 无限宽度并缩放至 \textwidth

tikzpicture 无限宽度并缩放至 \textwidth

我想告诉 tikz 制作一个图像,使其足够宽,以便正确绘制,然后将其缩放到\textwidth例如

\documentclass{article}
\usepackage{amsmath}
\usepackage[usenames]{color}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary {positioning,arrows.meta,graphs,shapes.misc}

\begin{document}
\newcommand{\z}[4]{
  \begin{minipage}{2cm}
    \begin{align*}
      Z\{&ini&=&#1\\
         &it&=&#2\\
         &coit&=&#3\\
         &curs&=&#4\}
    \end{align*}
  \end{minipage}
}
\begin{tikzpicture}[
  grow=right,
  edge from parent/.style={sloped,above,draw},
  level distance=7cm,
  sibling distance=4cm]

  \node {\z{p1,p2,p3}{\O}{\O}{p_0}}
  child {
    node {\z{p2,p3}{p_0}{\O}{p_1}}
    child {
      edge from parent node {pop init}
      node {\z{p_3}{p_1,p_0}{\O}{p_2}}
    }
    edge from parent node {pop init}
  }
  child {
    node {\z{p2,p3}{p_0'}{\O}{p_1}}
    edge from parent node  {pop it}
  };
\end{tikzpicture}
\end{document}

看起来 tikz 空间不足了

Tikz 决定在某个时候停止绘制

答案1

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\newcommand{\z}[4]{
  \begin{minipage}{2cm}
    \begin{align*}
      Z\{&ini&=&#1\\
         &it&=&#2\\
         &coit&=&#3\\
         &curs&=&#4\}
    \end{align*}
  \end{minipage}
}
\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[
  grow=right,
  edge from parent/.style={sloped,above,draw},
  level distance=7cm,
  sibling distance=4cm,
  ]
  \node {\z{p1,p2,p3}{\O}{\O}{p_0}}
  child {
    node {\z{p2,p3}{p_0}{\O}{p_1}}
    child {
      node {\z{p_3}{p_1,p_0}{\O}{p_2}}
      edge from parent node {pop init}
    }
    edge from parent node {pop init}
  }
  child {
    node {\z{p2,p3}{p_0'}{\O}{p_1}}
    edge from parent node  {pop it}
  };
\end{tikzpicture}}
\end{document}

具有四个节点的图

相关内容