如何使用森林创建反向方括号和花括号?

如何使用森林创建反向方括号和花括号?

使用 forest 包,我一直在构建一棵从西向东生长的树,并使用方括号和花括号连接父节点和子节点。是否有可能使用任何括号连接来自不同父节点的两个子节点?这是我现在拥有的代码:

\documentclass{article}
\usepackage{forest}

\begin{document}

\begin{forest}
    for tree={
        align=left, 
        grow=0,
        reversed,
        parent anchor=east,
        child anchor=west,
        edge path={
            \noexpand\path[\forestoption{edge}](!u.parent anchor) -- +(5pt,0) |- (.child anchor)\forestoption{edge label};},
        anchor=west, 
        }
[vestuário
    [frio]
    [calor
        [praia, edge=rounded corners
            [\\, edge=rounded corners
                [ggggggg]
                [hhhhhhhhhh]
            ]
            [\\, edge=rounded corners,
                [iiiiiiiii \\ \scriptsize $\searrow$ Ator+Meta; \\ \scriptsize \ \ \ \ Ator] 
                [jjjjjjjj]
        ]
        ]
        [eeeeeee, no edge] 
        [fffffffff, edge=rounded corners
            [kkkk]
            [llllllllllll]
        ]
    ]
    [\ \ \ \ \ \ ,name=arc01] 
]
\draw
    []([xshift=-5pt]arc01)
  arc[start angle=90,end angle=0,
  radius=0.5cm] 
  node [pos=1.2]{\textit{*}}; 
\end{forest}
\end{document} 

这是我想要的结果:

在此处输入图片描述

答案1

在 中没有非黑客的方法可以做到这一点forest。最简单的方法就是在 Ti 中进行注释Z 事后。如果你想要更多东西forest,你会遇到麻烦,因为不可能将增长速度提高 180 度。

\documentclass{standalone}% ref.: ateb JJSilva https://tex.stackexchange.com/a/651224/ i ei chwestiwn/gwestiwn ei hunain https://tex.stackexchange.com/q/651136/ 
% ateb: https://tex.stackexchange.com/a/690712/
\usepackage{forest}
\useforestlibrary{edges}
\forestset{%
  declare keylist={my icky keys}{},
  declare keylist register={annotated stages},
  declare boolean={adjuster}{0},
  declare toks={adjustment relative}{},
  adjust to me/.style={%
    adjuster,
    adjustment relative=#1,
  },
  icky keys/.style={
    paint the town/.style={red, edge=red, before computing xy={l:=2}},
    my icky keys={%
      for tree={
        if adjuster={
          typeout/.option=name,
          tempdima/.option=x,
          tempdima-/.process={Ow+O}{adjustment relative}{!{name=##1}.x},
          tempdimb/.option=y,
          tempdimb-/.process={Ow+O}{adjustment relative}{!{name=##1}.y},
          for name/.process={O}{adjustment relative}{for tree={x+/.register=tempdima,y+/.register=tempdimb}},
        }{},
      },
    },
  },
  annotated stages={% customised definition of stages
    for root'={% nothing is removed from the standard forest definition - we only change it by adding to it
      process keylist register=default preamble,
      process keylist register=preamble,
    },
    process keylist=given options,
    process keylist=before typesetting nodes,
    typeset nodes stage,
    process keylist=before packing,
    pack stage,
    process keylist=before computing xy,
    compute xy stage,
    % addition
    process keylist=my icky keys,
    process keylist=before drawing tree,
    draw tree stage,
  },
}
\begin{document}
\begin{forest}
  (%
    stages/.register=annotated stages,
  )%
  icky keys,
  for tree={
    forked edge,
    anchor=west, 
  },
  [,phantom,s sep=1cm
    [vestuário, for tree={grow=east}
      [frio]
      [calor
        [praia, edge=rounded corners
          [,  s sep:=3 
            [balde, name=f5, 
            ]
            [, phantom,    
              before computing xy={
                l*=2,
              }
              [, adjust to me=p7, for tree={grow=west, paint the town}, 
                [,name=p5, edge=rounded corners, tikz+={\draw [red] (f6.parent anchor) -- (.center);}]
                [,name=p6, edge=rounded corners, tikz+={\draw [red] (f5.parent anchor) -- (.center);}]
              ]
            ]
            [pá, name=f6]
          ]
          [
            [areia, name=f2, tikz+={\draw [red] (.parent anchor) -| (p20.child anchor) |- (f1.parent anchor);}]
            [castelo
              [, coordinate, no edge, name=p20
                [, coordinate, edge={->}, for tree={paint the town}, for children={fork sep'=0pt}, name=p3, 
                  [a]
                  [b]
                ]
              ]
            ]
          ]
        ]
        [deserto, no edge
        ]
        [Ásia, edge=rounded corners
          [norte]
          [sul, name=f1]
        ]
      ]
    ]
    [, coordinate, name=p7, for tree={grow=east, paint the town}
      [, coordinate, edge={->}, for children={fork sep'=0pt}
        [x]
        [y]
      ]
    ]
  ]
\end{forest}
\begin{forest}
  (%
    stages/.register=annotated stages,
  )%
  icky keys,
  for tree={
    forked edge,
    anchor=west, 
    grow'=0,
    align=left,
    if={>Ow+P{n children}{isodd(#1)}}{%
      for n/.process={Ow+P{n children}{int((#1+1)/2)} {calign with current edge}  },
    }{},
  },
  [, phantom, s sep'=10mm
    [vestuário
      [frio]
      [calor
          [praia, edge=rounded corners
              [, edge=rounded corners
                  [ggggggg]
                  [hhhhhhhhhh, name=f2, tikz+={\draw [red] (.parent anchor) -- (p20 |- .parent anchor) |- (f1.20 -| f1.70);}]
              ]
              [, phantom, before computing xy={
                  l*=2.5,
                }
                [, coordinate, adjust to me=p20, tier=align adjusters, for tree={grow=west}, paint the town]
              ]
              [, edge=rounded corners,
                  [iiiiiiiii \\ \scriptsize $\searrow$ Ator+Meta; \\ \scriptsize \ \ \ \ Ator, name=f1] 
                  [jjjjjjjj, name=f6]
          ]
          ]
          [eeeeeee, no edge] 
          [fffffffff, edge=rounded corners
              [kkkk 
                [, phantom, before computing xy={
                  l*=2,
                }
                  [, coordinate, adjust to me=p7, tier=align adjusters, for tree={grow=west, paint the town}
                    [,name=p5, edge=rounded corners, tikz+={\draw [red] (f6.parent anchor) -- (.center);}]
                    [,name=p6, edge=rounded corners, tikz+={\draw [red] (f5.parent anchor) -- (.center);}]
                  ]
                ]
              ]
              [llllllllllll,name=f5]
          ]
      ]
      [,name=arc01]
    ]
    [, coordinate, name=p7, for tree={grow=east, paint the town}
      [, coordinate, edge={->}, for children={fork sep'=0pt}
        [x]
        [y]
      ]
    ]
    [, coordinate, no edge, name=p20
      [, coordinate, edge={->}, for tree={paint the town}, for children={fork sep'=0pt}, name=p3, 
        [a]
        [b]
      ]
    ]
  ]
  \draw ([xshift=5pt]arc01)
  arc [start angle=90,end angle=0,radius=0.5cm] 
  node [pos=1.2]{\textit{*}}; 
\end{forest}

\end{document}

调整后的树木

如果我知道这需要多长时间,我就不会开始。我忘了我忘记了多少。

[如果我知道我也会编辑它,我可能也不会完成。]

答案2

这是我得到的最好的结果。我不知道如何排列红树,使其紧凑,就像问题中的图像一样。

\documentclass{standalone}
\usepackage{tikz}
\usepackage[edges]{forest}

\begin{document}

\begin{forest}
    for tree={
        forked edge,
        anchor=west, 
        }
[,phantom,s sep=1cm
[vestuário, for tree={grow=east}
    [frio]
    [calor
        [praia, edge=rounded corners
            [
                [balde, name=f5]
                [pá, name=f6]
            ]
            [
                [areia, name=f2]
                [castelo]
            ]
        ]
        [deserto, no edge
        ]
        [Ásia, edge=rounded corners
            [norte]
            [sul, name=f1]
        ]
    ]
]
[,for tree={grow=west, edge=red}, name=f3
[,name=p1]
[,name=p2]
]
[,for tree={grow=east, edge=red}, name=p3
[a, red]
[b, red]
]
[,for tree={grow=west, edge=red}, name=f7
[,name=p5, edge=rounded corners]
[,name=p6, edge=rounded corners]
]
[,for tree={grow=east, edge=red}, name=p7
[x,red]
[y, red]
]
]
\draw [->, red](f1) to (p1);
\draw [->, red](f2) to (p2);
\draw [->, red](f3) to (p3);
\draw [->, red](f5) to (p6);
\draw [->, red](f6) to (p5);
\draw [->, red](f7) to (p7);
\end{forest}

\end{document}

在此处输入图片描述

相关内容