Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have the following code to graph a function with a height of 2em, and in line with some text, but it gives an error.

\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.

Which is kinda silly considering I've removed the labels. I want an output like so:

expected result

share|improve this question
    
You can draw big and then put inside a \scalebox{<scale>}{plot}. Hiding axis lines or emptying the ticks don't mean that you skip the whole plotting mechanism (though plausible alternative). –  percusse Apr 6 at 10:46

1 Answer 1

up vote 11 down vote accepted

If you set scale only axis, there's no minimum height:

\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}
share|improve this answer
2  
Cool! I didn't know that. –  percusse Apr 6 at 11:05
    
Works perfectly! Thanks for fixing the spacing too, but I don't quite get how appending {} added empty space, I've never seen that trick before. –  mcjohnalds45 Apr 6 at 15:43
1  
@mcjohnalds45: take a look at tex.stackexchange.com/questions/31091 –  Jake Apr 7 at 8:37
    
Irrelevant comment: tex.stackexchange.com/a/170168/19356 –  stalking is prohibited Apr 8 at 23:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.