我有以下代码来绘制高度为 2em 的函数图,并与一些文本一致,但它给出了错误。
\documentclass{article}
\usepackage{pgfplots}
\newcommand\quadratic{
\begin{tikzpicture}
\begin{axis}[axis lines=none,height=2em]
\addplot[mark=none]{x^2};
\end{axis}
\end{tikzpicture}}
\begin{document}
This image \quadratic is a quadratic.
\end{document}
Package pgfplots Error: Error: Plot width `23.1882pt' is too small.
This cannot be implemented while maintaining constant size for labels.
Sorry, label sizes are only approximate. You will need to adjust your width.
考虑到我已经删除了标签,这有点愚蠢。我想要这样的输出:
答案1
如果设置scale only axis
,则没有最小高度:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\newcommand\quadratic{%
\begin{tikzpicture}
\begin{axis}[hide axis, scale only axis, height=2ex]
\addplot[mark=none]{x^2};
\end{axis}
\end{tikzpicture}}
\begin{document}
This image \quadratic{} is a quadratic.
\end{document}