我有以下代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\newlength{\cm}
\setlength{\cm}{1cm}
\newcommand\scalefactor{2}
\newcommand{\bintree}[5]{
\protect{\renewcommand\scalefactor{#5}}
\resizebox{\scalefactor\cm}{!}{%
\begin{tikzpicture}%
\draw (0,0)--(0,.5);%
\draw (0,.5)--(-.5,1);%
\draw (0,.5)--(.5,1);%
\node[below] at (0,0){#3};%
\node[above] at (-.5,1){#1};%
\node[above] at (.5,1){#2};%
\node[right] at (0,.4){#4};%
\end{tikzpicture}}}
\begin{document}
\bintree{$s$}{$s$}{$s$}{$*$}{1}
\bintree{$s$}{$s$}{$s$}{$*$}{3}
\end{document}
不幸的是,它似乎不起作用(我没有得到我想要的重新缩放)。这是我得到的结果:
日志中没有任何内容。我该如何修复此问题?
答案1
你已经在一个组内完成了重新定义,所以你可以这样做
\documentclass{article}
\usepackage{tikz}
\usepackage{graphicx}
\newlength{\cm}
\setlength{\cm}{1cm}
\newcommand\scalefactor{2}
\newcommand{\bintree}[5]{%
\renewcommand\scalefactor{#5}%
\resizebox{\scalefactor\cm}{!}{%
\begin{tikzpicture}%
\draw (0,0)--(0,.5);%
\draw (0,.5)--(-.5,1);%
\draw (0,.5)--(.5,1);%
\node[below] at (0,0){#3};%
\node[above] at (-.5,1){#1};%
\node[above] at (.5,1){#2};%
\node[right] at (0,.4){#4};%
\end{tikzpicture}}}
\begin{document}
\bintree{$s$}{$s$}{$s$}{$*$}{1}
\bintree{$s$}{$s$}{$s$}{$*$}{3}
\end{document}
尽管你根本不需要,\cm
或者\scalefactor
你可以这样做
\resizebox{#5cm}
并且从不应用\protect
它{
永远不会做任何有用的事情并且通常会产生奇怪的错误。