3

I am getting an error I cannot fix when compiling this minimal example. Please advise how to fix and continue. All suggestions welcome. Basically I am trying to add an arrowhead along the plot at any point desired.

The error I am getting is Dimension too large Error!

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[scale=.6,cap=round]
\tikzset{axes/.style={}}
 % The graphic
 \draw[style=help lines,step=1cm, dotted] (-4,-3.0) grid (7,9.0);
 \begin{scope}[style=axes]
 \draw[->] (-5,0) -- (8,0) node[below] {$x$};
 \draw[->] (0,-4)-- (0,10) node[left] {$y$};
 \foreach \x/\xtext in {-4/-4, -3/-3, -2/-2, -1/-1 , 1/\textcolor{red}{1}, 
       2/2, 3/3, 4/4, 5/5, 6/6,7/7}
 \draw[xshift=\x cm] (0pt,2.6pt) -- (0pt,-2.6pt) 
     node[below,fill=white,font=\scriptsize] {$\xtext$};
 \foreach \y/\ytext in {-3/-3, -2/-2, -1/-1, 1/1,   2/2, 3/\textcolor{cyan} 
     {3}, 4/4, 5/5, 6/6 , 7/7 , 8/8 , 9/9}
  \draw[yshift=\y cm] (2.6pt,0pt) -- (-2.6pt,0pt) 
   node[left,fill=white,font=\scriptsize]
    {$\ytext$};
   \draw[domain=3:4,smooth,variable=\x,red,->,thick,postaction={decorate, 
       decoration={markings,
       mark=at position 0.5 with {\arrow{<};}}}
       ] plot ({\x},{1+2*\x});
    \draw[domain=-3:3,smooth,variable=\x,red,<-,thick] plot ({\x},{4-\x}); 
   \draw[fill=white,draw=red,thick] (3,7) circle (3pt) node[] {$$};
   \draw[red,fill=red] (3,1) circle (3pt) node[] {};
    \node at (5,8) [fill=white,text=red,font=\normalsize] {$k(x)$};
   \end{scope}
  \draw[draw=cyan,fill=cyan,opacity=.3] (2.85,-3) rectangle (3.15,9);   
\end{tikzpicture}
\end{document}

enter image description here

4
  • Yes, this happens if you do a lot of transformations. The problem goes away if you replace scale=0.6 by scale=1. (Honestly, I am also surprised that it already happens for scale=0.6.) If you tell us precisely what you want, I am sure there will be a simple way to produce it without issues.
    – user121799
    Nov 11 '18 at 15:12
  • The output is correct but I am trying to get rid of the error. Unfortunately, I cannot change the scale=1. I have to leave it at scale=.6. I see this eliminates the error. I am trying to read the document on the marking library Nov 11 '18 at 15:18
  • Yes, but if you drop smooth, which is superfluous in a straight line, the error will also disappear.
    – user121799
    Nov 11 '18 at 15:18
  • Thanks Marmot I thought I had already tried that and now the error is gone! Nov 11 '18 at 15:21
1

Why does that happen? It is a combination of smooth and scale=0.6. In this case, in which you only plot a straight line, smooth has no visible effect. However, one could imagine that you want to plot something where smooth does have a visible effect. What to do then? Just draw the thing and use a non-smooth path for adding the arrow.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}
\begin{tikzpicture}[scale=0.6,cap=round]
\tikzset{axes/.style={}}
 % The graphic
 \draw[style=help lines,step=1cm, dotted] (-4,-3.0) grid (7,9.0);
 \begin{scope}[style=axes]
 \draw[->] (-5,0) -- (8,0) node[below] {$x$};
 \draw[->] (0,-4)-- (0,10) node[left] {$y$};
 \foreach \x/\xtext in {-4/-4, -3/-3, -2/-2, -1/-1 , 1/\textcolor{red}{1}, 
       2/2, 3/3, 4/4, 5/5, 6/6,7/7}
 \draw[xshift=\x cm] (0pt,2.6pt) -- (0pt,-2.6pt) 
     node[below,fill=white,font=\scriptsize] {$\xtext$};
 \foreach \y/\ytext in {-3/-3, -2/-2, -1/-1, 1/1,   2/2, 3/\textcolor{cyan} 
     {3}, 4/4, 5/5, 6/6 , 7/7 , 8/8 , 9/9}
  \draw[yshift=\y cm] (2.6pt,0pt) -- (-2.6pt,0pt) 
   node[left,fill=white,font=\scriptsize]
    {$\ytext$};
   \draw[red,->,thick] plot[domain=3:4,smooth,variable=\x] ({\x},{1+2*\x});
   \path[postaction={decorate, 
       decoration={markings,
       mark=at position 0.5 with {\arrow[red,thick]{<};}}}] 
       plot[domain=3:4,variable=\x] ({\x},{1+2*\x});   

    \draw[domain=-3:3,smooth,variable=\x,red,<-,thick] plot ({\x},{4-\x}); 
   \draw[fill=white,draw=red,thick] (3,7) circle (3pt) node[] {$$};
   \draw[red,fill=red] (3,1) circle (3pt) node[] {};
    \node at (5,8) [fill=white,text=red,font=\normalsize] {$k(x)$};
   \end{scope}
  \draw[draw=cyan,fill=cyan,opacity=.3] (2.85,-3) rectangle (3.15,9);   
\end{tikzpicture}
\end{document}

enter image description here

1
  • Any advice for a later plot that is not a straight line ? and I cannot use scale=1.? You answered this question above as well. Thanks Marmot! Nov 11 '18 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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