我正在尝试使用 lualatex 0.79(通过 MikTeX2.9)来生成带有“间谍”气泡的 TikZ 图片,但在尝试缩放整体图片时发现一个问题——被监视的“气泡”并没有出现在我预期的位置。
以下是示例代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[htbp]
\centering
\begin{tikzpicture}[spy using outlines={circle, magnification=3,size=1cm, connect spies},scale=0.63,every node/.style={transform shape}]
\begin{axis}[%
domain=0:3000, restrict y to domain=-1:1,
width=4.520833in,height=3.565625in,
at={(0.758333in,0.48125in)},
scale only axis,
xmin=0,xmax=3000,
scaled y ticks = false,
ymin=-0.05,ymax=0.05,
xmajorgrids,ymajorgrids,
xlabel={x-label},
]
\coordinate (spypoint1) at (axis cs:0,0);
\coordinate (spypoint2) at (axis cs:500,0.02);
\end{axis}
\spy on (spypoint1) in node at (spypoint2);
\end{tikzpicture}
\end{figure}
\end{document}
包含“scale=0.63,every node/.style={transform shape}”会导致问题(因为间谍气泡不在我期望的位置(在“spypoint1”和“spypoint2”给出的坐标处)),而排除这个(即使用名义缩放)是可以的。
我这样做是否不正确?(我也想缩放文本 - 因此,在 tikzpicture 中使用‘scale’,而不是‘axis’。)
如有任何建议/解决方案,我们将不胜感激!
谢谢,
迈克尔
答案1
您可以将整个 tikzpicture 放在里面\scalebox{<scale>}{<tikzpicture>}
。
输出
代码
\documentclass{article}
\usepackage{tikz}
\usepackage{tikzscale}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\pgfplotsset{compat=newest}
\begin{document}
\begin{figure}[htbp]
\centering
\scalebox{.63}{
\begin{tikzpicture}[spy using outlines={circle, magnification=3,size=1cm, connect spies}]
\begin{axis}[%
domain=0:3000, restrict y to domain=-1:1,
width=4.520833in,height=3.565625in,
at={(0.758333in,0.48125in)},
scale only axis,
xmin=0,xmax=3000,
scaled y ticks = false,
ymin=-0.05,ymax=0.05,
xmajorgrids,ymajorgrids,
xlabel={x-label},
]
\coordinate (spypoint1) at (axis cs:0,0);
\coordinate (spypoint2) at (axis cs:500,0.02);
\end{axis}
\spy on (spypoint1) in node at (spypoint2);
\end{tikzpicture}}
\end{figure}
\end{document}