将多个图形放在一个-tikz中

将多个图形放在一个-tikz中

我画了几棵树,现在我想把它们放在一个图形中(并排或一个在另一个下面)

 \documentclass{report}

 \usepackage{tikz}
 \usetikzlibrary{fit,shapes}

 \begin{document}
 %First picture
 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 
 \tikzstyle{level 1}=[sibling distance=40mm] 
 \tikzstyle{level 2}=[sibling distance=20mm] 
 \tikzstyle{level 3}=[sibling distance=10mm] 
 \node (S) {S} 
  child{node (n) {N} child{node (mary) {mary}} }
  child{node (VP) {VP}     
        child{node{V} child{node(des){brought }}}
        child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } }
   ; 


  \end{tikzpicture}
   %Second picture
  \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 
  \tikzstyle{level 1}=[sibling distance=40mm] 
  \tikzstyle{level 2}=[sibling distance=20mm] 
  \tikzstyle{level 3}=[sibling distance=10mm] 
  \node (VP) {VP}     
        child{node{V} child{node(des){brought }}}
        child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } ;


  \end{tikzpicture}
  %Third picture
 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 

 \node(V){V}
     child{node(des){brought }};

\end{tikzpicture}


  %fourth picture
 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt},] 

  \node (np){NP}
         child{node{D} child{node{a}} }
        child{node{N} child{node{a}} };


 \end{tikzpicture}

 % ..... the other picture
 \end{document}

所以我想做这样的事情:

在此处输入图片描述

答案1

如果你正在绘制语言树,你真的应该使用tikz-qtree包。输入语法不仅更加简单,它还会自动为您分隔节点。至于定位,您可以使用\scopes 来表示较大的部分,甚至可以使用简单的\hspaces 来排列部分:

\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}

\begin{tikzpicture}
\Tree [.S 
        [.NP [.N Mary ]]
        [.VP [.V brought ] 
             [.NP [.D a ] [.N cat ]]
        ]
      ]
\begin{scope}[xshift=6cm]
\Tree [.VP [.V brought ] 
             [.NP [.D a ] [.N cat ]]
        ]
\end{scope}
\begin{scope}[xshift=9cm]
\Tree [.NP [.D a ] [.N cat ]]
\end{scope}
\begin{scope}[xshift=6cm,yshift=-4cm]
\Tree [.N cat ]
\hspace{1.25cm}
\Tree [.D a ]
\hspace{1.25cm}
\Tree [.N Mary ]
\hspace{1.25cm}
\Tree [.V brought ] 
\end{scope}
\end{tikzpicture}
\end{document}

代码输出

答案2

你好,你可以使用相对定位,这基本上允许你说我想要节点 X y 远离 Y:

 \documentclass{report}

 \usepackage{tikz}
 \usetikzlibrary{fit,shapes, positioning}

 \begin{document}

 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt}, every node/.append style={font=\tiny}] 
 \tikzstyle{level 1}=[sibling distance=20mm] 
 \tikzstyle{level 2}=[sibling distance=14mm] 
 \tikzstyle{level 3}=[sibling distance=10mm] 
 \node  (S) at (0,0) {S} 
  child{node (n) {N} child{node (mary) {mary}} }
  child{node (VP) {VP}     
        child{node{V} child{node(des){brought }}}
        child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } }
   ; 

  \node (VP)  [right= 5cm of S]{VP}     
        child{node{V} child{node(des){brought }}}
        child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } ;


  \node (np) [right= 4cm of VP]{NP}
         child{node{D} child{node{a}} }
        child{node{N} child{node{a}} };

 \node(V) [below= 7cm of VP]{V}
     child{node(des){brought }};

 \end{tikzpicture}

 \end{document}

有关相对定位系统的更多信息,另请参阅 tikz/pgf 指南。上述示例将跨越页面边界。您可以尝试调整文本大小和同级距离,直到您满意为止。

更新 虽然我不太喜欢这个想法,但我想告诉你,可以把所有这些树放到一棵树中,并告诉 tikz 不要绘制第一层(或者将其绘制为白色,如下所示)。

 \documentclass{report}

 \usepackage{tikz}
 \usetikzlibrary{fit,shapes, positioning}

 \begin{document}

 \begin{tikzpicture}[every fit/.style={ellipse,draw,red,inner sep=-2pt}, every node/.append style={font=\tiny}] 
\tikzstyle{level 1}=[sibling distance=37mm] 
\tikzstyle{level 2}=[sibling distance=25mm] 
\tikzstyle{level 3}=[sibling distance=15mm] 
\tikzstyle{level 4}=[sibling distance=10mm] 

\node  (S) at (0,0) {}[edge from parent/.style={draw,white,thick},level distance=1mm]
child{node{a}
          child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{D} child{node{a}} }
         child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{N} child{node{a}} }}
child{node{PP}
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} } }
        %  
child{node{S}
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (n) {N} child{node (mary) {mary}} }
        child[edge from parent/.style={draw,red,thick},level distance=20mm]{node (VP) {VP}%
          child{node{V} child{node(des){brought }}}
          child{node (np) {NP}   child{node{D} child{node (a) {a}}} child{node{N} child{node (cat) {cat}}}  }
          child{node{PP}  child{node{IN} child{node{to}}}     child{node{N}  child{node{school}}} }} 
}


        ;

 \end{tikzpicture}

 \end{document}

我不喜欢这个的原因应该很清楚:我们必须明确地告诉 tikz 我们希望后续级别是什么样子,因为在树中,在较高级别给出的选项将被传递到树的末尾。

相关内容