![tikz 环境中的填充和缩放选项问题](https://linux22.com/image/364915/tikz%20%E7%8E%AF%E5%A2%83%E4%B8%AD%E7%9A%84%E5%A1%AB%E5%85%85%E5%92%8C%E7%BC%A9%E6%94%BE%E9%80%89%E9%A1%B9%E9%97%AE%E9%A2%98.png)
当我尝试缩放 tikzpicture 时遇到问题。以下代码
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\begin{document}
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elitsit amet ante
lobortis sollicitudin. Praesent blandit blandit mauris. Praesentlectu
tellus, aliquet aliquam, luctus a, egestas a, turpis. Mauris lacinia
loremsit amet ipsum. Nunc quis urna dictum turpis accumsan semper.
\begin{center}
\begin{tikzpicture}[scale=0.7]
\begin{axis}[
unit vector ratio*=1 1 1,
axis lines=middle,
xmin=-3, xmax=3,
ymin=-3, ymax=3,
xtick=\empty, ytick=\empty
]
\addplot [name path=f, domain=-2.2:2.2, samples=2] {x};
\addplot [name path=g, domain=-3:3, samples=2, dashed] {x+2};
\addplot[pattern=north west lines, pattern color=gray] fill between[
of=g and f,
soft clip={domain=-3:3}
];
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
生产
图表覆盖在文本上。如果我删除比例选项或部分之间的填充,一切就都正常了。
提前致谢
答案1
缩放tikzpicture
似乎会对边界产生一些奇怪的影响,但将 添加到scale
选项中axis
,效果就很好了。或者(我认为通常这样做更有意义),设置width
的axis
。
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{patterns}
\usepgfplotslibrary{fillbetween}
\begin{document}
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elitsit amet ante
lobortis sollicitudin. Praesent blandit blandit mauris. Praesentlectu
tellus, aliquet aliquam, luctus a, egestas a, turpis. Mauris lacinia
loremsit amet ipsum. Nunc quis urna dictum turpis accumsan semper.
\begin{center}
\begin{tikzpicture}
\begin{axis}[
% scale=0.7, % this works
width=7cm, % and so does this (but no need for both)
unit vector ratio*=1 1 1,
axis lines=middle,
xmin=-3, xmax=3,
ymin=-3, ymax=3,
xtick=\empty, ytick=\empty
]
\addplot [name path=f, domain=-2.2:2.2, samples=2] {x};
\addplot [name path=g, domain=-3:3, samples=2, dashed] {x+2};
\addplot[pattern=north west lines, pattern color=gray] fill between[
of=g and f,
soft clip={domain=-3:3}
];
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}