我有以下代码来调整大小,tikzpicture
仅当它太宽时:
\documentclass{article}
\usepackage{tikz}
\usepackage{environ}
\newsavebox\mybox
\newenvironment{resizedtikzpicture}[1]{%
\def\mywidth{#1}%
\begin{lrbox}{\mybox}%
\begin{tikzpicture}
}{%
\end{tikzpicture}%
\end{lrbox}%
\if\wd\mybox>\mywidth
\resizebox{\mywidth}{!}{\usebox\mybox}%
\else
\usebox\mybox %
\fi
}
\begin{document}
\begin{resizedtikzpicture}{\textwidth}
\end{resizedtikzpicture} % line 69
\end{document}
但它给了我以下错误:
! Missing number, treated as zero.
<to be read again>
\unhbox
l.69 \end{resizedtikzpicture}
我不明白这是怎么unhbox
回事。我该如何修复此错误?我做错了什么?
答案1
\if\wd\mybox>\mywidth
应该
\ifdim\wd\mybox>\mywidth