当我尝试缩放 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}