相关片段:

相关片段:

我想创建一个自定义环境,自动将语法树扩展至特定宽度。我xparse在我的环境中使用 LaTeX3 语法。

相关片段:

我想\resizebox{.8\textwidth}{!}{在环境的开始部分包括一个,并}在环境的结束部分包括一个。

\NewDocumentEnvironment{syntaxtree}{ O{remember picture} }
        {\begin{center}\begin{tikzpicture}[#1]}
        {\end{tikzpicture}\end{center}}

完整代码

\documentclass{article}
\usepackage[log-declarations=false]{xparse}
\usepackage[quiet]{fontspec}
\usepackage{tikz}
\usepackage{tikz-qtree}

% Colors
\definecolor{retrogreendark}{cmyk}{.45,.18,.94,.38}
\definecolor{retrobluedark}{cmyk}{.53,.20,.18,.01}
\definecolor{retroyellowdark}{cmyk}{.08,.34,.94,.15}
\definecolor{retroorangedark}{cmyk}{.02,.52,.92,.03}
\definecolor{retropinkdark}{cmyk}{.08,.87,.88,.16}
\definecolor{retroreddark}{cmyk}{.12,.88,.94,.35}

\tikzset{
    % Valid for All Trees
    font=\small,
    level 1+/.style={text=retroorangedark},
    level 2+/.style={text=retropinkdark},
    level 3+/.style={text=retrobluedark},
    every tree node/.style={align=center, anchor=south,text depth=0pt},
    every leaf node/.append style={text depth=0pt,font=\bfseries,text=retroreddark},
    level distance=1cm,
    every node/.style={
        inner sep=0pt,
        outer sep=3pt,
    },
edge from parent path={(\tikzparentnode.south)[] .. controls +(0,-.15) and +(0,.25) ..(\tikzchildnode.north)}, %controls shape of tree branches
    wordclass/.style={
        color=retrogreendark,
        edge from parent/.append style={dashed}
    }
}

 \NewDocumentEnvironment{syntaxtree}{ O{remember picture} }
    {\begin{center}\begin{tikzpicture}[#1]}
    {\end{tikzpicture}\end{center}}

\begin{document}
\section{Colorless green ideas sleep furiously.}
\begin{syntaxtree}[level 5+/.style={wordclass}]
    \Tree
    [.{Sentence}
        [.{Subject}
            [.{NP}
                    [[.A \node[](colorless){Colorless}; ]]
                    [.NP 
                        [.adj. \node[](green){green}; ]
                        [.n. \node[](ideas){ideas}; ]]]]%done
        [.{Predicate}
            [.VP
                    [[.v. \node[](sleep){sleep};    ]]
                    [[.adv. \node[](furiously){furiously.};]]]]]
\end{syntaxtree}
\end{document}

在此处输入图片描述

答案1

使用盒子:

\newsavebox{\syntaxtreebox}
\NewDocumentEnvironment{syntaxtree}{ O{} }
  {\begin{lrbox}{\syntaxtreebox}\begin{tikzpicture}[remember picture,#1]}
  {\end{tikzpicture}\end{lrbox}%
   \begin{center}\resizebox{0.8\textwidth}{!}{\usebox{\syntaxtreebox}}\end{center}}

我已经改变了该选项的语法remember picture;否则如果您为环境指定一个可选参数,它将不会被设置。

在此处输入图片描述

相关内容