代码

代码

我有一个不适合幻灯片的 tikz 树。主题和行距已给出,所以我只想更改 tikz 节点中文本的行距。但对我来说没什么用 :(

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage[utf8]{inputenc}

\setbeamertemplate{navigation symbols}{}

\linespread{1.35}

\usepackage[ngerman]{babel}
\usepackage{graphicx}
\usepackage{array}
\usepackage[light]{iwona}
\usepackage{color, colortbl}
\usepackage{tikz}
\begin{document}
\begin{frame}{Dependency Tree Kernel (Culotta 2004)}
\begin{columns}
    \begin{column}[T]{0.5\linewidth}
        \begin{tikzpicture}[scale=0.7,
            n/.style={rectangle, draw, rounded corners=1mm,
            align=center, anchor=north},
            level 1/.style={sibling distance=2cm}, 
            level distance=0.5cm, growth parent anchor=south,
            transform shape]

            \node [n] (a1){became\\Verb\\-\\-}
            child {
                node [n] (a2) {Recently\\Adverb\\-\\-}
            }   
            child {
                node[n] (a3) {Obama\\Noun\\PER\\Arg1}
            }
            child {[sibling distance=1.5cm]
                node[n] (a4) {president\\Noun\\PER\\-}
                child{[sibling distance=1.1cm]
                    node[n] 
                        (a5) {the\\Det\\-\\-}
                }
                child {
                    node[n] (a6) {of\\Prep\\-\\-}
                    child {
                        node[n] (a7) {USA\\Noun\\ORG\\Arg2}
                        child{[sibling distance=1.1cm]
                            node[n] 
                                (a8) {the\\Det\\-\\-}
                        }
                    }    
                }
            };
        \end{tikzpicture}        
    \end{column}
    \hspace{-6ex}
    \begin{column}[T]{0.5\linewidth}
        \begin{tikzpicture}[scale=0.7, 
            n/.style={rectangle, draw, rounded corners=1mm,
            align=center, anchor=north},
            level 1/.style={sibling distance=2cm}, 
            level distance=0.5cm, growth parent anchor=south,
            transform shape]

            \node [n] (is){is\\Verb\\-\\-}
            child {
                node [n] (Ballmer) {Ballmer\\Noun\\PER\\Arg1}
            }   
            child {
                node[n] (still) {still\\Adverb\\-\\-}
            }
            child {[sibling distance=1cm]
                node[n] (CEO) {CEO\\Noun\\-\\-}
                child{[sibling distance=1.1cm]
                    node[n] 
                        (the) {the\\Det\\-\\-}
                }
                child {
                    node[n] (of) {of\\Prep\\-\\-}
                    child {
                        node[n] (Microsoft) {Microsoft\\Noun\\ORG\\Arg2}
                    }    
                }
            };
        \end{tikzpicture}
    \end{column} 
\end{columns}
\end{frame}
\end{document}

在此处输入图片描述

答案1

插入 环境\linespread{1}\selectfont 中第一个节点定义之上tikzpicture

答案2

由于columns环境仅包含树木,您可能希望将参数设置\linespread1仅针对columns环境。

此外,该forest软件包使得绘制语言树变得更加容易。

代码

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage[utf8]{inputenc}

\setbeamertemplate{navigation symbols}{}

\linespread{1.35}

\usepackage[ngerman]{babel}
\usepackage{array}
\usepackage[light]{iwona}
\usepackage{forest}
\begin{document}

\begin{frame}{Dependency Tree Kernel (Culotta 2004)}
\begin{columns}\linespread{1}
  \begin{column}[T]{0.5\linewidth}
    \centering
    \begin{forest}
      for tree={align=center,scale=.7,transform shape,draw,rectangle,rounded corners=1mm}
      [became\\Verb\\-\\-,
        [Recently\\Adverb\\-\\-,]
        [Obama\\Noun\\PER\\Arg1,]
        [president\\Noun\\PER\\-,
          [the\\Det\\-\\-]
          [of\\Prep\\-\\-
            [USA\\Noun\\ORG\\Arg2]
          ]
        ]
      ]
    \end{forest}
  \end{column}
  \begin{column}[T]{0.5\linewidth}
    \centering
    \begin{forest}
      for tree={align=center,scale=.7,transform shape,draw,rectangle,rounded corners=1mm}
      [is\\Verb\\-\\-
        [Ballmer\\Noun\\PER\\Arg1]
        [still\\Adverb\\-\\-]
        [CEO\\Noun\\-\\-
          [the\\Det\\-\\-]
          [of\\Prep\\-\\-
            [Microsoft\\Noun\\ORG\\Arg2]
          ]
        ]
      ]
    \end{forest}
  \end{column}
\end{columns}
\end{frame}
\end{document}

输出

在此处输入图片描述

答案3

这是修改后的版本Kevin C 的回答展示如何使用样式来减少排版树所需的代码并确保一致性。这是否有用可能取决于您要制作多少这样的树!

.wrap value用于自动将语言类别添加到节点。因此,Microsoft\\Noun\\ORG\\Arg2您可以写而不是Microsoft, noun org arg2。如果您需要经常使用它,您可能希望将样式名称缩写一点,以便您可以写Microsoft, noa2或任何其他名称。但是使用较长的名称更容易理解代码,并且最好选择您自己的缩写,以便它们对您有意义。

\documentclass{beamer}
\beamertemplatenavigationsymbolsempty
\usepackage[utf8]{inputenc}
\usepackage[light]{iwona}
\usepackage{forest}
\forestset{
  noun/.style={
    content/.wrap value={##1\\Noun\\--\\--},
  },
  noun per/.style={
    content/.wrap value={##1\\Noun\\PER\\--},
  },
  noun per arg1/.style={
    content/.wrap value={##1\\Noun\\PER\\Arg1},
  },
  noun org arg2/.style={
    content/.wrap value={##1\\Noun\\ORG\\Arg2},
  },
  det/.style={
    content/.wrap value={##1\\Det\\--\\--},
  },
  prep/.style={
    content/.wrap value={##1\\Prep\\--\\--},
  },
  adverb/.style={
    content/.wrap value={##1\\Adverb\\--\\--},
  },
  verb/.style={
    content/.wrap value={##1\\Verb\\--\\--},
  },
  my tree/.style={
    for tree={align=center, scale=.7, transform  shape, draw, rectangle, rounded corners=1mm},
  },
}
\begin{document}

\begin{frame}{Dependency Tree Kernel (Culotta 2004)}
\begin{columns}\linespread{1}
  \begin{column}[T]{0.5\linewidth}
    \centering
    \begin{forest}
      my tree
      [became, verb
        [Recently, adverb
        ]
        [Obama, noun per arg1
        ]
        [president, noun per
          [the, det
          ]
          [of, prep
            [USA, noun org arg2
            ]
          ]
        ]
      ]
    \end{forest}
  \end{column}
  \begin{column}[T]{0.5\linewidth}
    \centering
    \begin{forest}
      my tree
      [is, verb
        [Ballmer, noun per arg1
        ]
        [still, adverb
        ]
        [CEO, noun
          [the, det
          ]
          [of, prep
            [Microsoft, noun org arg2
            ]
          ]
        ]
      ]
    \end{forest}
  \end{column}
\end{columns}
\end{frame}
\end{document}

森林风格

相关内容