# How to fix the problem, dimension too large although the tikzpicture is fit on the page?

\documentclass[10pt]{book}
\usepackage[paperheight=9in,paperwidth=7in, top=1in, bottom=0.8in, twocolumn, twoside]{geometry}
\setlength{\columnseprule}{0.4pt}
\usepackage{tikz-cd}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage[centertags]{amsmath}
%\usepackage{amsfonts}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}
\usepackage{epsfig}
\usepackage{graphicx}\graphicspath{{Graphics/}}
\usepackage{amsthm}
\usepackage{mathptmx}
\usepackage[square,sort&compress]{natbib}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
%\usepackage{mathrsfs}
\usetikzlibrary{arrows}
%\usepackage{amssymb,latexsym}
%\usepackage{amsfonts,amsmath}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{textcomp}
%\usepackage{amsmath,amssymb}
\usepackage{latexsym}
%\usepackage{amsfonts}
\usepackage[arrow,frame,matrix]{xy}
%\usepackage{fixltx2e}
\usepackage{xcolor}
\usepackage{setspace}
\usepackage{booktabs}
\renewcommand{\baselinestretch}{1.5}
\newcommand\aug{\fboxsep=-\fboxrule\!\!\!\fbox{\strut}\!\!\!}
\theoremstyle{definition}
\newtheorem{Thm}{Theorem}[section]
\newtheorem{lem}[Thm]{Lemma}
\newtheorem{pro}[Thm]{Proposition}
\newtheorem{de}[Thm]{Definition}
\newtheorem{re}[Thm]{Remark}
\newtheorem{ex}[Thm]{Example}
\newtheorem{cor}[Thm]{Corollary}
\numberwithin{equation}{section}
\definecolor{uuuuuu}{rgb}{0.26666666666666666,0.26666666666666666,0.26666666666666666}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=0.70cm,y=0.70cm]
\begin{axis}[
x=0.70cm,y=0.70cm,
axis lines=middle,
xmin=-2.5,
xmax=4.2,
ymin=-0.5,
ymax=4.5,
xtick={-2.0,-1.0,...,4.0},
ytick={-0.0,1.0,...,4.0},]
\clip(-2.5,-0.5) rectangle (4.2,4.5);
\draw[line width=1.0pt,smooth,samples=100,domain=-2.5:4.2] plot(\x,{(\x)^(2.0)});
\draw[line width=1.0pt,smooth,samples=100,domain=-2.5:4.2] plot(\x,{(\x)^(4.0)});
\draw[line width=1.0pt,smooth,samples=100,domain=-2.5:4.2] plot(\x,{(\x)^(6.0)});
\draw [line width=1.0pt] (1.4070657529753525,1.9798340331960957)-- (2.593941214963645,1.978475622020055);
\draw [line width=1.0pt] (1.2953304783336062,2.81528481157305)-- (3.041192850857456,2.80084143919352);
\draw [line width=1.0pt] (1.2392646000958023,3.6222987404404536)-- (2.997910434480636,3.5943523154135297);
\draw (2.6829479881822733,2.412164593764555) node[anchor=north west] {${\small y=x^2}$};
\draw (2.9931087994563645,3.306157418205916) node[anchor=north west] {${\small y=x^4}$};
\draw (2.9931087994563645,4.017702727455162) node[anchor=north west] {${\small y=x^6}$};
\end{axis}
\end{tikzpicture}
\end{document}


The tikzpicture is fit in the column not crossing the page anywhere, but still I am getting the error. I can't work with sizes bigger than about 19 feet. Continue and I'll use the largest value I can.

! Dimension too large. How can I fix this problem?

• Pgfmath converts text to lengths to FPU registers and back again, with the limiting factor being lengths (32K or 100K). Easiest is to compute the data externally and read them in using pgfplotstable. There are also tricks using \pgfmathparsefpu (see tex.stackexchange.com/questions/545405/…) – John Kormylo Jul 11 at 18:01
• @JohnKormylo Brother I need changes in tikzpicture code, I have share, The plot is fit and still I have problem of dimension too large, what to change in it? – Noor Aslam Jul 11 at 18:04
• First of all, try to avoid using a^b. In general, a^b is computed using exp(b*log(a)) instead of a*a or a*a*a etc. That may not fix it, but it is far better from an applied math point of view. – John Kormylo Jul 12 at 19:10

You restrict the vertical axis with ymax but the draw commands you are using to plot have horizontal domains that (for the given functions) result in values that are far outside (above) the border of the picture that is actually printed. Hence, the error dimension too large.

Set domain=-2.3:2.3 and it all works fine.

You can restricted function values, i.e. y, to domain defined by restrict y to domain=<min>:<max>:

\documentclass[twocolumn, twoside]{book}
\usepackage[paperheight=9in,paperwidth=7in,
top=1in, bottom=0.8in]{geometry}
\setlength{\columnseprule}{0.4pt}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage{textcomp}

\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usetikzlibrary{arrows,
intersections}

\begin{document}
\begin{tikzpicture}[
line cap=round, line join=round,
>=triangle 45]
\begin{axis}[
x=0.7 cm,y=0.7 cm,
axis lines=middle,
xlabel=$x$,
ylabel=$y$,
label style = {anchor=west},
xmin=-3.3,  xmax=3.3,
ymin=-0.5,  ymax=4.5,
restrict y to domain=-0.5:4,    % <---
clip=false,
xtick={-3,-1,...,3},
ytick={0,1,...,4},
samples=400,
domain=-3:3,
no marks,
every axis plot post/.append style={line width=1.0pt,
color=blue!50}
]
%
\path [name path=C2] (0,3.5) -- (2.5,3.5);
\path [name path=C4] (0,3.0) -- (2.5,3.0);
\path [name path=C6] (0,2.5) -- (2.5,2.5);
%
\coordinate (n) at (2.5,0);
\draw [name intersections={of=c2 and C2, by=a}, <-]
(a) -- (a -| n) node[right] {$y=x^2$};
\draw [name intersections={of=c4 and C4, by=b}, <-]
(b) -- (b -| n) node[right] {$y=x^4$};
\draw [name intersections={of=c6 and C6, by=c}, <-]
(c) -- (c -| n) node[right] {$y=x^6$};
\end{axis}
\end{tikzpicture}
\end{document}


As you can observe, the code for labeling of curves is written from scratch. It employ intersections TikZ library, so no need to manually calculated arrows for positioning of arrows and labels.