我想定义一个新环境,使 Tikz 中的图形更容易制作:
\newenvironment{tikzc}[7]
{\begin{center}
\begin{tikzpicture}[scale=#1]
\pgfmathsetmacro{\xmini}{#2};
\pgfmathsetmacro{\xmaxi}{#3};
\pgfmathsetmacro{\ymini}{#4};
\pgfmathsetmacro{\ymaxi}{#5};
\begin{axis}[xmin=\xmini,xmax=\xmaxi,ymin=\ymini,ymax=\ymaxi,axis lines=center, clip = false, xtick=\empty, ytick=\empty]
\node[scale=0.1] (y) at (\xmini,\ymaxi){};
\node[scale=0.1] (x) at (\xmaxi,\ymini){};
\node[left= 0.09cm of x,scale=0.5] (xlabel) at ([yshift=-0.12cm]$(x)$){#6};
\node[left= 0.04cm of y,scale=0.5] (ylabel) at ([yshift=-0.11cm]$(y)$){#7};
}
{\end{axis}
\end{tikzpicture}
\end{center}
}
但我明白
“扫描使用 \path 时文件结束”为什么?
答案1
您的宏有效。因此,您可能向其输入了触发错误的某些内容。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\usetikzlibrary{positioning,calc}
\newenvironment{tikzc}[7]
{\begin{center}
\begin{tikzpicture}[scale=#1]
\pgfmathsetmacro{\xmini}{#2};
\pgfmathsetmacro{\xmaxi}{#3};
\pgfmathsetmacro{\ymini}{#4};
\pgfmathsetmacro{\ymaxi}{#5};
\begin{axis}[xmin=\xmini,xmax=\xmaxi,ymin=\ymini,ymax=\ymaxi,axis lines=center, clip = false, xtick=\empty, ytick=\empty]
\node[scale=0.1] (y) at (\xmini,\ymaxi){};
\node[scale=0.1] (x) at (\xmaxi,\ymini){};
\node[left= 0.09cm of x,scale=0.5] (xlabel) at ([yshift=-0.12cm]$(x)$){#6};
\node[left= 0.04cm of y,scale=0.5] (ylabel) at ([yshift=-0.11cm]$(y)$){#7};
}
{\end{axis}
\end{tikzpicture}
\end{center}
}
\begin{document}
\begin{tikzc}{1}{0}{10}{0}{5}{$x$}{$y$}
\addplot[very thick,red,domain=0:5] {0.04*x^2};
\end{tikzc}
\end{document}
编辑:将 移到\begin{document}
之后\newenvironment...
。