factor
s的比例因子xtick
不适用于 ldots mask ...
。这个问题有解决方案吗?
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
%===============================================================================
\begin{document}
\noindent
\begin{tikzpicture}[
declare function ={
factor=2;
}
]
\begin{axis}[
%xtick = {-2*factor,2*factor}, % This one work
%xtick = {-2,...,2}, % This one work
xtick = {-2*factor,...,2*factor}, % This one doesn't work
]
\addplot+[blue, no marks, domain={-6:6}] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您需要设置/pgf/foreach/parse=true
,请参阅 pgfmanual v3.1.4 第 989 页
这是有效的(至少在这种情况下)。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
%===============================================================================
\begin{document}
\noindent
\begin{tikzpicture}[/pgf/foreach/parse=true,%<-added
declare function ={
factor=2;
}
]
\begin{axis}[
%xtick = {-2*factor,2*factor}, % This one work
%xtick = {-2,...,2}, % This one work
xtick={-2*factor,...,2*factor}, % This one works now
]
\addplot+[blue, no marks, domain={-6:6}] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
我要说的是,我建议不要过度使用它parse=true
,在处理整数的情况时我遇到了一些困难。
万一您在使用此提案时遇到问题,因为其他一些(可能是内部)循环导致问题:您还可以使用xtickmin
和xtickmax
,其值会自动解析。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
%===============================================================================
\begin{document}
\noindent
\begin{tikzpicture}[
declare function ={
factor=2;
}
]
\begin{axis}[
xtickmin=-2*factor,
xtickmax=2*factor,
]
\addplot+[blue, no marks, domain={-6:6}] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}