使用森林和投影機避免跳躍樹中的節點

使用森林和投影機避免跳躍樹中的節點

手冊中有一些關於避免跳躍的內容,這裡進行了解釋避免投影機中的跳幀以及。但我在樹上的情況可能有所不同。有沒有辦法避免下面程式碼中兩個圖形之間的跳躍?

\documentclass{beamer}

\usepackage{forest}

% http://tex.stackexchange.com/questions/167690/presenting-a-forest-tree-from-bottom-to-top-in-beamer
% showing and hiding nodes and edges in forest
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\forestset{
  visible on/.style={
    for tree={
      /tikz/visible on={#1},
      edge={/tikz/visible on={#1}}}}}

\newcommand{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\upshape\scshape #1}\right\rangle$}%
}

% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
    for tree={align=center,parent anchor=south, child anchor=north,anchor=north,base=bottom},
    before drawing tree={
      sort by=y,
      for min={tree}{baseline}
    }
  }}


\forestset{
  declare dimen={child anchor yshift}{0pt},
  adjust childrens child anchors/.style={
    if n children>=2{
      before packing={
        tempdima/.max={max_y}{children},
        for children={
          child anchor yshift=tempdima()-max_y()
        },
      }
    }{}
  },
  default preamble={
    for tree={
      edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
      adjust childrens child anchors
    }
  },
}


\begin{document}

\frame{

\begin{forest}
[S
 [\alt<1>{XP}{NP1234}]
 [\alt<1>{YP}{NP1234}]
 [\alt<1>{ZP}{NP1234}]
 [\ldots, visible on=<1>]
 [{\alt<1>{H}{V} \sliste{ \alt<1>{XP}{NP}, \alt<1>{YP}{NP}, \alt<1>{ZP}{NP}\visible<1>{, \ldots} }}
   [{V \sliste{ NP, NP, NP }}, visible on=<1>,no edge]]]
\end{forest}

\pause

}


\end{document}

編輯:透過添加 1234 使 NP 更長,以便跳躍非常明顯。

答案1

這可能是解決問題的第一步。我添加了一個min width可以傳遞兩個不同文字的密鑰。是的,如果可以更改為自動執行此操作會更好\alt,但由於擴展問題我無法執行此操作。 (我什至不知道我正在對抗誰的擴張,beamer或者forest。)

\documentclass{beamer}

\usepackage{forest}

% http://tex.stackexchange.com/questions/167690/presenting-a-forest-tree-from-bottom-to-top-in-beamer
% showing and hiding nodes and edges in forest
\tikzset{
    invisible/.style={opacity=0,text opacity=0},
    visible on/.style={alt=#1{}{invisible}},
    alt/.code args={<#1>#2#3}{%
      \alt<#1>{\pgfkeysalso{#2}}{\pgfkeysalso{#3}} % \pgfkeysalso doesn't change the path
    },
}
\forestset{
  visible on/.style={
    for tree={
      /tikz/visible on={#1},
      edge={/tikz/visible on={#1}}}}}

\newcommand{\sliste}[1]{%
\mbox{%
$\left\langle\mbox{\upshape\scshape #1}\right\rangle$}%
}

% specification for all trees, "default preamble" appends to existing specification.
% The version with apostrophe replaces it.
\forestset{default preamble'={
    for tree={align=center,parent anchor=south, child anchor=north,anchor=north,base=bottom},
    before drawing tree={
      sort by=y,
      for min={tree}{baseline}
    }
  }}


\forestset{
  declare dimen={child anchor yshift}{0pt},
  adjust childrens child anchors/.style={
    if n children>=2{
      before packing={
        tempdima/.max={max_y}{children},
        for children={
          child anchor yshift=tempdima()-max_y()
        },
      }
    }{}
  },
  default preamble={
    for tree={
      edge path'={(!u.parent anchor)--([yshift=\forestoption{child anchor yshift}].child anchor)},
      adjust childrens child anchors
    }
  },
}


\begin{document}
\tikzset{min width/.style n args={2}{/utils/exec={\pgfmathparse{max(width("#1"),width("#2"))}
 \edef\mywidth{\pgfmathresult}},
 text width={\mywidth pt}}}
\frame{

\begin{forest}
[S
 [\alt<1>{XP}{NP1234},min width={XP}{NP1234}]
 [\alt<1>{YP}{NP1234},min width={YP}{NP1234}]
 [\alt<1>{ZP}{NP1234},min width={ZP}{NP1234}]
 [\ldots, visible on=<1>]
 [{\alt<1>{H}{V} \sliste{ \alt<1>{XP}{NP}, \alt<1>{YP}{NP}, \alt<1>{ZP}{NP}\visible<1>{, \ldots} }}
   [{V \sliste{ NP, NP, NP }}, visible on=<1>,no edge]]]
\end{forest}

\begin{tikzpicture}[overlay,remember picture] 
\draw[red] (current page.south west) grid (current page.north east); 
\end{tikzpicture}
\pause

}


\end{document}

在此輸入影像描述

紅色網格只是為了引導眼睛。

相關內容