un albero con tikz

  • Creatore
    Topic
  • #94757
    claudio
    Partecipante
      Up
      0
      Down
      ::


      Sto facendo delle prove per disegnare alberi (anche se il termine è improprio )
      usando forest
      ho scritto il seguente codice
      `
      \documentclass{article}
      \usepackage{forest}
      \usetikzlibrary{arrows}
      \usetikzlibrary{decorations}
      \begin{document}

      \begin{forest}
      for tree={
      child anchor=west,
      parent anchor=east,
      grow=east,
      anchor=west,
      edge path={
      \noexpand\path[\forestoption{edge}]
      (.child anchor) -| +(-5pt,0) — +(-5pt,0) |-
      (!u.parent anchor)\forestoption{edge label};
      },
      pred/.style={draw},
      edge=<-=triangle 45 }, [{A},pred , align=center, [{V} [C,pred,name=P] [D,pred [F,name=F]]; [E,pred] ] [V [AA,pred] ] ] ]; \end{forest} \end{document} ` il problema è che la foglia F dovrebbe essere figlia di C e D si può fare o mi conviene forest e passare ad altro? a me serve una strutture [soggetto]-->verbo—>[complemento]
      saluti
      claudio

    Visualizzazione 4 filoni di risposte
    • Autore
      Risposte
      • #94758
        claudio
        Partecipante
          Up
          0
          Down
          ::


          altra soluzione
          `
          \documentclass{article}
          \usepackage[utf8]{inputenc}
          \usepackage{tkz-graph}
          \usetikzlibrary{arrows}
          \thispagestyle{empty}
          \begin{document}
          \begin{center}
          \begin{tikzpicture}[>=latex']
          \tikzset{VertexStyle/.style = {
          shape = rectangle,
          inner sep = 0pt,
          outer sep = 0pt,
          minimum size = 50pt,
          draw}}
          \SetGraphUnit{4}
          \Vertex[L=A]{P}
          \NOEA[L=B](P){M}
          \EA[L=C](P){D}
          \SOEA[L=D](M){C}
          \tikzset{EdgeStyle/.style={->}}
          \Edge[label=1](P)(M)
          \Edge[label=1](P)(D)
          \Edge[label=2](M)(C)
          \Edge[label=2](D)(C)
          \end{tikzpicture}
          \end{center}
          \end{document}
          `
          difetto di questa soluzione
          definire shape diverse da usare contemporaneamente
          è un tantino rognoso se si può dire
          ciao
          claudio

        • #94759
          claudio
          Partecipante
            Up
            0
            Down
            ::


            ultimo per oggi
            `
            \documentclass[tikz,border=10pt]{standalone}
            \usetikzlibrary{positioning,calc}
            \tikzset{main node/.style={rectangle, draw,
            text width=5em, text centered, rounded corners, minimum height=4em}, }
            \tikzset{main verb/.style={minimum size=1cm,inner sep=0pt}, }
            \begin{document}
            \begin{tikzpicture}
            \node[main node] (1) {N};
            \node[main verb] (2)

            {h};
            \node[main node] (3) [below right = 1cm and 1cm of 2] {B};
            \node[main node] (4) [above right = 1cm and 1cm of 2] {C};
            \path let \p1=(3), \p2=(4) in node[main verb] (5) at (\x1+60,\y2/2+\y1/2){h};
            \node[main node] (6)

            {D};
            \node[main verb] (7) [below = 2cm of 1] {s};
            \node[main node] (8) [below = 2cm of 6] {E};
            \path let \p1=(6), \p2=(8) in node[main verb] (9) at (\x1+60,\y2/2+\y1/2){F};
            \node[main node] (10)

            {G};
            \path[draw,->] (1) edge node {} (2);
            \path[draw,->] (2) edge node {} (3);
            \path[draw,->] (2) edge node {} (4);
            \path[draw,->] (4) edge node {} (5);
            \path[draw,->] (3) edge node {} (5);
            \path[draw,->] (5) edge node {} (6);
            \path[draw,->] (1) edge node {} (7);
            \path[draw,->] (7) edge node {} (8);
            \path[draw,->] (6) edge node {} (9);
            \path[draw,->] (9) edge node {} (10);
            \path[draw,->] (8) edge node {} (9);
            \end{tikzpicture}
            \end{document}
            `

            credo che sia la soluzione migliore
            che ne pensate?
            claudio

          • #94760
            Up
            0
            Down
            ::


            Con forest, hai sempre la possibilità di usare TikZ. Io posizionerei a mano il nodo F che deve essere figlio di C e D: `
            \documentclass{article}
            \usepackage{forest}
            %\usetikzlibrary{arrows}% in questo esempio non serve
            %\usetikzlibrary{decorations}% in questo esempio non serve
            \usetikzlibrary{calc}

            \begin{document}

            \begin{forest}
            for tree={
            child anchor=west,
            parent anchor=east,
            grow=east,
            anchor=west,
            edge path={
            \noexpand\path[\forestoption{edge}]
            (.child anchor) -| +(-5pt,0) — +(-5pt,0) |-
            (!u.parent anchor)\forestoption{edge label};
            },
            pred/.style={draw},
            edge=<-=triangle 45 }, [{A},pred , align=center, [{V} [C,pred,name=C] [D,pred,name=D] [E,pred] ] [V [AA,pred] ] ] ]; \node[draw](F) at ($(C.east)!0.5!(D.east)+(1,0)$){F};% posizione \draw[->](C.east)-|($(C)!0.5!(F)$)|-($(F.south west)!0.5!(F.west)$);
            \draw[->](D.east)-|($(D)!0.5!(F)$)|-($(F.north west)!0.5!(F.west)$);
            \end{forest}
            \end{document}
            ` Non capisco perché non ti piaccia la sintassi [tt]\draw[/tt], ma preferisci [tt]\path[draw,..][/tt] che è identica e più lunga.

            Ciao
            Claudio

          • #94761
            claudio
            Partecipante
              Up
              0
              Down
              ::


              ok ma se F è padre di un alberello?
              ciao e grazie
              claudio

            • #94762
              Up
              0
              Down
              ::

              claudio” post=94398ok ma se F è padre di un alberello?
              ciao e grazie
              claudio

              Crea un nuovo albero con forest (nello stesso ambiente) con la radice ancorata in F che è un punto noto.

              Ciao
              Claudio

          Visualizzazione 4 filoni di risposte
          • Devi essere connesso per rispondere a questo topic.

          Go to top