![为什么有些 tikz 图片可以缩放,而有些则不能?](https://linux22.com/image/470341/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%9C%89%E4%BA%9B%20tikz%20%E5%9B%BE%E7%89%87%E5%8F%AF%E4%BB%A5%E7%BC%A9%E6%94%BE%EF%BC%8C%E8%80%8C%E6%9C%89%E4%BA%9B%E5%88%99%E4%B8%8D%E8%83%BD%EF%BC%9F.png)
尝试使用 tikzpicture 的缩放选项,发现有些图片可以使用,有些则不行。我不知道为什么。
这是 MWE
以下是代码
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\usepackage[margin=1in]{geometry}
\tikzstyle{block} = [rectangle, draw=red, text centered, rounded corners, minimum height=1cm]
\begin{document}
\noindent\fbox{\begin{tikzpicture}[scale=3]
\node [block, minimum width=2in] at (0,0) (A) {text};
\node [block, below =of A] (B) {more test};
\draw[->] (A)--(B);
\end{tikzpicture}
}
And
\noindent\fbox{\begin{tikzpicture}[scale=1]
\node [block, minimum width=2in] at (0,0) (A) {text};
\node [block, below =of A] (B) {more test};
\draw[->] (A)--(B);
\end{tikzpicture}
}
\noindent\fbox{\begin{tikzpicture}[scale=3]
\draw (0,0) -- (1,1);
\end{tikzpicture}
}
\noindent\fbox{\begin{tikzpicture}[scale=1]
\draw (0,0) -- (1,1);
\end{tikzpicture}
}
\end{document}
为什么第二个可以,第一个就不行?我一直以为整个图片都会缩放。
TL 2023
答案1
如果您想缩放节点,您还需要提供该transform shape
选项(旋转也是如此,irc):
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,fit}
\usepackage[margin=1in]{geometry}
\tikzstyle{block} = [rectangle, draw=red, text centered, rounded corners, minimum height=1cm]
\begin{document}
\noindent\fbox{\begin{tikzpicture}[scale=3, transform shape]
\node [block, minimum width=2in] at (0,0) (A) {text};
\node [block, below =of A] (B) {more test};
\draw[->] (A)--(B);
\end{tikzpicture}
}
And
\noindent\fbox{\begin{tikzpicture}[scale=1]
\node [block, minimum width=2in] at (0,0) (A) {text};
\node [block, below =of A] (B) {more test};
\draw[->] (A)--(B);
\end{tikzpicture}
}
\noindent\fbox{\begin{tikzpicture}[scale=3]
\draw (0,0) -- (1,1);
\end{tikzpicture}
}
\noindent\fbox{\begin{tikzpicture}[scale=1]
\draw (0,0) -- (1,1);
\end{tikzpicture}
}
\end{document}