숲을 위한 더 작은 지붕

숲을 위한 더 작은 지붕

나는 다음과 같은 나무를 가지고 있습니다. 지붕이 텍스트만큼 넓지 않고 넓기를 원합니다. 로 이 작업을 수행할 수 있는 방법이 있나요 forest? 특히 상단 텍스트의 너비여야 합니다. 이는 번역이 원본 텍스트보다 훨씬 더 넓은 경우에 중요합니다. 지붕은 분석된 것이기 때문에 원본 텍스트에 맞아야 하며, 번역은 추가적이고 논리적으로 구조의 일부가 아닙니다.

\documentclass{minimal}

\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word}{}}}, 
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
}


\begin{document}

\begin{forest}
sn edges
[NP
  [Det [das\\the] ]
  [N'
    [N'
      [N [Bild\\picture] ]
      [PP [vom Gleimtunnel\\of.the Gleimtunnel,triangle ] ] ] 
    [PP [im Gropiusbau\\in.the Gropiusbau,triangle ] ] ] ]
\end{forest}

\end{document}

편집하다:아래 Sašo의 거의 완벽한 솔루션이 있습니다. 그러나 한 가지 문제가 남아 있습니다. \trace트리에서 사용하고 싶은 명령을 정의했습니다 . 번역 코드와 함께 사용하면 다음 오류가 발생합니다.

! Argument of \@rsbox has an extra }.
<inserted text> 
                \par 
l.45 \end{forest}

?

코드는 다음과 같습니다.

\documentclass{minimal}   

\usepackage{forest}



\forestset{
  with translation/.style={
    l sep=0,inner xsep=0,
    append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
    content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
  },  
  append translation/.style={append={[#1,no edge,l=0,inner xsep=0,inner ysep=0,outer ysep=0,before
        computing xy={l-=2pt}]}},
  sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top},
                           where n children=0{tier=word,delay=with translation}{} %,delay=with translation
                          }
}


\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}





\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}

\begin{document}


\begin{forest}
sn edges
[NP
  [Det [eine;a] ]
  [N$'$
    [A [kluge;smart] ]
    [N$'$
      [N [\trace ] ] ] ] ]
\end{forest}

\end{document}

\end{forest}

번역된 트리에서 이러한 명령을 허용하는 방법이 있습니까?

답변1

아래에서는 포리스트 매뉴얼(섹션 4.2)의 큰 예에 표시된 트릭을 사용하여 노드의 내용을 구문 분석했습니다. 그런 다음 (i) 추가 노드가 텍스트 바로 아래에 생성되고 번역(즉, \\원본 콘텐츠 뒤에 오는 모든 항목)으로 채워지고 (ii) 번역이 콘텐츠에서 삭제됩니다. (이 구문 분석 메커니즘은 트리의 모든 리프에 적용되도록 설정됩니다.)

또한 텍스트 및 번역 노드에 대해 를 설정하여 삼각형이 텍스트에 꼭 맞도록 tikz합니다 inner xsep.0

편집: 번역 없이 노드를 허용하도록 코드가 변경되었습니다. 그러나 이 작업은 더 간단한 구분 기호로만 수행할 수 있었습니다. 아래에서 ;사용됩니다.

두 번째 편집: .expanded스타일의 핸들러 append translation는 추가 문제를 처리하기 위해 체인 content으로 대체되었습니다 (OP의 편집된 질문 참조)..expand once.expand twice\trace

\documentclass{minimal}   
\usepackage{forest}

\forestset{
  with translation/.style={
    l sep=0,inner xsep=0,
    append translation/.expand once/.expand twice/.wrap pgfmath arg={\gettranslation{##1}}{content},
    content/.expand once/.expand twice/.wrap pgfmath arg={\gettext{##1}}{content},
  },  
  append translation/.style={append={[#1,no edge,l=0,inner xsep=0,inner ysep=0,outer ysep=0,before
        computing xy={l-=2pt}]}},
  sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top},
                           if n children=0{tier=word,delay=with translation}{} %,delay=with translation
                          }
}

\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}


\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}
\begin{document}

\begin{forest}
sn edges,
[NP
  [Det [das] ]
  [N'
    [N'
      [N [Bild;picture] ]
      [PP [vom Gleimtunnel;of.the Gleimtunnel,triangle]] ] ] 
    [PP [im Gropiusbau;in.the Gropiusbau,triangle ] ] ] ]
\end{forest}

\begin{forest}
sn edges
[NP
  [Det [eine;a] ]
  [N$'$
    [A [kluge;smart] ]
    [N$'$
      [N [\trace ] ] ] ] ]
\end{forest}

\end{document}

세 번째 편집: where n children=0정의 내에서 sn edges논리적으로 더 정확한 것으로 변경되었습니다 if n children=0. 이는 패키지의 현재(v1.0.10) 버전에서는 아무런 차이가 없지만(더 느리게 실행되는 것을 제외하고) where n children패키지의 (향후) v1.1에서는 잘못된 결과를 생성합니다. 이는 v1.1에서 delay. v1.0.x에서는 delay단일 노드에서 를 두 번 이상 사용하면 첫 번째 호출을 잊어버렸습니다. 따라서 위 코드의 잘못된 버전은 delay=with translation두 번 이상 호출되었음에도 불구하고 v1.0.x에서 작동합니다. delay=with translation세 번 호출하면 실제로 (나중에) 세 번 호출되는 v1.1에서는 with translation불필요한 빈 노드가 생성됩니다.

답변2

한 가지 옵션:

\documentclass{article}
\usepackage{forest}

\forestset{
sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=bottom,where n children=0{tier=word,inner xsep=0pt,outer sep=0pt}{}}}, 
background tree/.style={for tree={text opacity=0.2,draw opacity=0.2,edge={draw opacity=0.2}}}
}

\newcommand\HideWd[1]{%
  \makebox[0pt]{#1}%
}


\begin{document}

The default behaviour:\par
\begin{forest}
sn edges,
[NP
  [Det [das\\the] ]
  [N',s sep=20pt
    [N',s sep=15pt
      [N [Bild\\picture] ]
      [PP [vom Gleimtunnel\\ of.the Gleimtunnel,triangle ] ] ] 
    [PP [im Gropiusbau\\ in.the Gropiusbau,triangle ] ] ] ]
\end{forest}

Hiding the wider text:\par
\begin{forest}
sn edges,
[NP
  [Det [das\\the] ]
  [N'
    [N'
      [N [Bild\\picture] ]
      [PP [vom Gleimtunnel\\ \HideWd{of.the Gleimtunnel},triangle ] ] ] 
    [PP [im Gropiusbau\\ \HideWd{in.the Gropiusbau},triangle ] ] ] ]
\end{forest}

Hiding the wider text and correcting the separation:\par
\begin{forest}
sn edges,
[NP
  [Det [das\\the] ]
  [N',s sep=20pt
    [N',s sep=15pt
      [N [Bild\\picture] ]
      [PP [vom Gleimtunnel\\ \HideWd{of.the Gleimtunnel},triangle ] ] ] 
    [PP [im Gropiusbau\\ \HideWd{in.the Gropiusbau},triangle ] ] ] ]
\end{forest}

\end{document}

여기에 이미지 설명을 입력하세요

아이디어는 더 넓은 텍스트를 "숨기기" 위해 0pt 너비의 상자를 사용하는 것입니다(이것이 명령이 \HideWd수행하는 작업입니다). 그러나 이는 영향을 받은 형제 사이의 거리 계산에 바람직하지 않은 영향을 미치므로(이미지의 두 번째 나무 참조) 적절한 값을 제공하기 위해 수동 개입이 필요합니다 s sep(이미지의 세 번째 3개 참조). .

답변3

이것은 주어진 코드를 결합하는 문제와 관련하여 편집된 질문에 대한 답변입니다.Sašo Živanović의 답변사용자 정의 매크로를 사용하여.

\trace트릭은 트리에서 의 사용을 새로운 스타일로 바꾸는 것입니다 . 이 스타일은 매크로를 실행하고 자식이 0인 노드에 대한 trace적용을 재정의합니다 .with translation

\documentclass[tikz, border=5pt]{standalone}
\usepackage{forest}
\forestset{
  sn edges/.style={for tree={parent anchor=south, child anchor=north,align=center,base=top}, for tree={where n children=0{tier=word, delay=with translation}{}}},
  trace/.style={
    replace by={[\trace, delay={}, tier=word]}
  },
  with translation/.style={
    l sep=0,
    inner xsep=0,
    append translation/.expanded/.wrap pgfmath arg={\gettranslation{##1}}{content},
    content/.expanded/.wrap pgfmath arg={\gettext{##1}}{content},
  },
  append translation/.style={
    append={
      [
        #1,
        no edge,
        l=0,
        inner xsep=0,
        inner ysep=0,
        outer ysep=0,
        before computing xy={
          l-=2pt
        }
      ]
    },
  },
}

\def\gettext#1{\gettextA#1;;\endget}
\def\gettextA#1;#2;{\removesep#1;}
\def\gettranslation#1{\gettranslationA#1;;\endget}
\def\gettranslationA#1;#2;{\removesep#2;}
\def\removesep#1;#2\endget{#1}

\newcommand{\trace}{\raisebox{0.2ex}{\_}\rule{0cm}{0.7em}}

\begin{document}

  \begin{forest}
    sn edges
    [NP
      [Det [eine;a] ]
      [N$'$
        [A [kluge;smart] ]
        [N$'$
          [N [, trace ] ] ] ] ]
  \end{forest}

\end{document}

추적 및 번역

관련 정보