如何解决 pgf 中与网格放置相关的错误?

如何解决 pgf 中与网格放置相关的错误?

我一直在尝试生成图表,但遇到了下面提到的代码的错误。我哪里做错了?请帮忙。

Package pgfkeys Error: I do not know the key '/tikz/graphs/grid placement' 

梅威瑟:

\documentclass{article} % say
\usepackage{tikz}
%\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
%\usegdlibrary{trees}

%\usetikzlibrary{graphs, graphs.standard}


\begin{document}

\begin{tikzpicture} 

%[level distance=10mm,
%every node/.style={fill=red!60,circle,inner sep=1pt},
%level 1/.style={sibling distance=20mm,nodes={fill=red!45}},
%level 2/.style={sibling distance=10mm,nodes={fill=red!30}},
%level 3/.style={sibling distance=5mm,nodes={fill=red!25}}]
%\node {31}
%child {node {30}
%child {node {20}
%child {node {5}}
%child {node {4}}
%}
%child {node {10}
%child {node {9}}
%child {node {1}}
%}
%}
%child {node {20}
%child {node {19}
%child {node {1}}
%child[missing]
%}
%child {node {18}}
%};


%[level distance=10mm,sibling distance=5mm]
%\node {root} [grow=down]
%child
%{ node {1} }
%child
%{ node {2} }
%child
%{ node {3} }
%child[missing] { node {4} }
%child
%{ node {5} }
%child
%{ node {6} };


%[edge from parent/.style={draw,red,thick}]
%\node {root}
%child {node {left} edge from parent[dashed]}
%child {node {right}
%child {node {child}}
%child {node {child} edge from parent[draw=none]}
%};


%\graph [binary tree layout, level %distance=5mm] {
%4 -- {
%3 -- 0 -- 1[second],
%10 -- {
%8 -- {
%6 -- {5,7},
%9
%} } }
%};

\begin{graph}[noplacement, n=6,nodes={draw}] {
      a, b, c, d, e, f,
     };
\end{graph}     


%\graph [nodes={draw, circle}, clockwise, %radius=.75cm, empty nodes, n=8] {
%subgraph C_n [name=inner] <->[shorten %<=1pt, shorten >=1pt]
%subgraph C_n [name=outer]
%};

%\graph [grow right=2cm] { unsigned integer %-> d -> digit -> E };

%\graph [tree layout, grow=down, fresh %nodes, level distance=0.5in, sibling %distance=0.5in]
%    {
%        4 -> { 
%          3 -> { 1 -> { 5}, 2,2 },
%          3 -> { 1, 2, 2 },
%          3 -> { 1, 2, 2 }
%        } 
%    };

[every path/.style={>=latex},every node/.style={draw,circle}]
  \node            (a) at (0,0)  { A };
  \node            (b) at (2,0)  { B };
  \node            (c) at (2,-2) { C };
  \node[rectangle] (d) at (0,-2) { D };
  \draw[->] (a) edge (b);
  \draw[->] (a) edge (c);
  \draw[->] (b) edge (c);
  \draw[<-] (c) edge (d);

 \begin{graph}[noplacement,nodes={draw,circle},edges={>=latex}] {
    A [at={(0,0)}] -> {
      B [at={(2,0)}] -> C [at={(2,-2)}],
      C -> D [at={(0,-2)},rectangle]
    }
  };
\end{graph}
\end{tikzpicture} 

\end{document}

答案1

no placement只要您不省略单词之间的空格,它就可以按广告的方式工作。

no placement适用于您需要手动指定节点位置的情况,但第一个图似乎并非如此。

有一个键grid placement。但是,如果您不使用subgraph,则必须wrap after明确指定,因为它无法自动计算。我认为这就是您对第一个图表想要的。

例如,同样将第二组和第三组向右移动以查看每组的效果:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphs}
\begin{document}
\begin{tikzpicture}
  \begin{graph}[grid placement, n=6, nodes={draw}, wrap after=3] {
      a, b, c, d, e, f,
    };
  \end{graph}
  \begin{scope}[every path/.style={>=latex}, every node/.style={draw, circle}, xshift=30mm]
    \node            (a) at (0,0)  { A };
    \node            (b) at (2,0)  { B };
    \node            (c) at (2,-2) { C };
    \node[rectangle] (d) at (0,-2) { D };
    \draw[->] (a) edge (b);
    \draw[->] (a) edge (c);
    \draw[->] (b) edge (c);
    \draw[<-] (c) edge (d);
  \end{scope}
  \begin{scope}[xshift=60mm]
    \begin{graph}[no placement, nodes={draw, circle}, edges={>=latex}, ] {
        A [at={(0,0)}] -> {
          B [at={(2,0)}] -> C [at={(2,-2)}],
          C -> D [at={(0,-2)},rectangle]
        }
      };
    \end{graph}
  \end{scope}
\end{tikzpicture}
\end{document}

网格放置,标准,无自动放置

相关内容