I am trying to generate a LaTeX pgfplot:

xlabel=Distance a (nm),
ylabel=Force F (mJ/nm)


This generates the error "dimension too large." What could be wrong?

  • 2
    Welcome to TeX.SX! The number range and the precision supported by TikZ are limited. Try to rewrite the formulas to avoid that intermediate results get out of range or divisors get too close to zero. Commented Apr 19, 2017 at 5:47
  • The error goes away when I used one less zero for ymax. That is,1e-16.
    – Troy
    Commented Apr 19, 2017 at 5:48
  • 3
    Welcome to TeX.SE. For future reference, while code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Commented Apr 19, 2017 at 5:57
  • 2
    you are way past tex's numerical accuracy there so specifying a range from essentially 0 to 0 . Even with a few less zeros so it doesn't error, you will just be getting essentially rounding error for the y values Commented Apr 19, 2017 at 8:23
  • 1
    Did my answer help you to solve your problem or do you need further assistance? If so, please let us know what you are still missing. Thank you. Commented Apr 22, 2017 at 9:28

1 Answer 1


The error is caused due to a "scaling" problem which can be avoided when you change the domain to the values near the range that is "visible" in the total plot. So simply narrowing down domain to 0.3:0.5 avoids the error.

% used PGFPlots v1.14
        xlabel=Distance a (nm),
        ylabel=Force F (mJ/nm),
        % ---------------------------------------------------------------------
        % changed `domain' to "visible" part of the plots to avoid
        % the "dimension to large" error
        % ---------------------------------------------------------------------
        % added `smooth' so the plots look better
        \addplot [color=black] {(((6.42*10^(-22))*6)/(x^7))-(((1.02*10^(-25))*13)/(x^14))};
        \addplot [color=red]   {(((6.42*10^(-22))*6)/(x^7))};
        \addplot [color=blue]  {-(((1.02*10^(-25))*13)/(x^14))};

image showing the result of above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .