1

Hi People I am at a lost how to add the arrows I want to this image. Below is the image/ minimal example and my goal as well. I need help adding the arrows:

\documentclass{article}

\usepackage{tikz,geometry}

\begin{document}

\begin{minipage}{.5\textwidth}
\begin{tikzpicture}
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [red,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
 (.5,1) (1.25,.5) (2.75,1) (4.5,2.5) (6,1.75) };
\filldraw[black] (1.25,.5) circle (2pt) node[] {$$};
\filldraw[black] (4.5,2.5) circle (2pt) node[] {$$};
\draw (1.25,0) node[below] {\scriptsize $a$} -- (1.25,.5) -- (0,0.5) node 
  [left] {\scriptsize $f(a)$};
\draw (4.5,0) node[below] {\scriptsize $b$} -- (4.5,2.5) -- (0,2.5) node 
  [left] {\scriptsize $f(b)$};
\node at (2.75,-1) [align=left] {\scriptsize If the input $a$ is less than 
  the input $b$,\\ \scriptsize then the output for $a$ is less than the\\ 
  \scriptsize output for $b$.};
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [blue,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
  (.5,2.5) (1.25,2.6) (2.75,1) (4.5,.5) (6,1.25)  };
\filldraw[black] (1.25,2.6) circle (2pt) node[] {$$};
\filldraw[black] (4.5,.5) circle (2pt) node[] {$$};
\draw (1.25,0) node[below] {\scriptsize $a$} -- (1.25,2.6) -- (0,2.6) node 
 [left] {\scriptsize $f(a)$};
\draw (4.5,0) node[below] {\scriptsize $b$} -- (4.5,.5) -- (0,.5) node 
 [left] {\scriptsize $f(b)$};
\node at (2.75,-1) [align=left] {\scriptsize If the input $a$ is less than 
  the input $b$,\\ \scriptsize then the output for $a$ is greater than the\\ 
  \scriptsize output for $b$.};
\end{tikzpicture}
\end{minipage}

\end{document}

This outputs:

enter image description here

I am trying add the "increasing" and "decreasing" arrows as in:

enter image description here

MathScholar
  • 2,513

1 Answers1

3

Like this?

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\begin{document}

\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[font=\scriptsize ]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [red,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
 (.5,1) (1.25,.5) (2.75,1) (4.5,2.5) (6,1.75) };
\filldraw[black] (1.25,.5) circle (2pt) coordinate (start);
\filldraw[black] (4.5,2.5) circle (2pt) coordinate (end);
\path (start) -- (end) node[midway,above,draw=red,single arrow,fill=red!20,sloped]{increasing};
\draw (1.25,0) node[below] {$a$} -- (1.25,.5) -- (0,0.5) node 
  [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,2.5) -- (0,2.5) node 
  [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is less than the\\ 
  output for $b$.};
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[font=\scriptsize]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [blue,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
  (.5,2.5) (1.25,2.6) (2.75,1) (4.5,.5) (6,1.25)  };
\filldraw[black] (1.25,2.6) circle (2pt) coordinate (start);
\filldraw[black] (4.5,.5) circle (2pt) coordinate (end);
\path (start) -- (end) node[midway,above,draw=blue,single
arrow,fill=blue!20,sloped]{decreasing};
\draw (1.25,0) node[below] {$a$} -- (1.25,2.6) -- (0,2.6) node 
 [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,.5) -- (0,.5) node 
 [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is greater than the\\ 
  output for $b$.};
\end{tikzpicture}
\end{minipage}
\end{document}

enter image description here

You could also have the arrow below, of course.

\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows}
\begin{document}

\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[font=\scriptsize ]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [red,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
 (.5,1) (1.25,.5) (2.75,1) (4.5,2.5) (6,1.75) };
\filldraw[black] (1.25,.5) circle (2pt) coordinate (start);
\filldraw[black] (4.5,2.5) circle (2pt) coordinate (end);
\path (start) -- (end) node[midway,below=14pt,draw=red,single arrow,fill=red!20,sloped]{increasing};
\draw (1.25,0) node[below] {$a$} -- (1.25,.5) -- (0,0.5) node 
  [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,2.5) -- (0,2.5) node 
  [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is less than the\\ 
  output for $b$.};
\end{tikzpicture}
\end{minipage}
\begin{minipage}{.5\textwidth}
\begin{tikzpicture}[font=\scriptsize]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [blue,<->,thick] plot [smooth,tension=.7,samples=200] coordinates { 
  (.5,2.5) (1.25,2.6) (2.75,1) (4.5,.5) (6,1.25)  };
\filldraw[black] (1.25,2.6) circle (2pt) coordinate (start);
\filldraw[black] (4.5,.5) circle (2pt) coordinate (end);
\path (start) -- (end) node[midway,above,draw=blue,single
arrow,fill=blue!20,sloped]{decreasing};
\draw (1.25,0) node[below] {$a$} -- (1.25,2.6) -- (0,2.6) node 
 [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,.5) -- (0,.5) node 
 [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is greater than the\\ 
  output for $b$.};
\end{tikzpicture}
\end{minipage}
\end{document}

enter image description here

Another possibility is to use decorations.markings for that, as detailed on p. 587 of the pgfmanual.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{shapes.arrows,decorations.markings}

\begin{document}
\foreach \X in {0.2,0.225,...,0.8}
{\begin{tikzpicture}[font=\scriptsize ]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [red,<->,thick,postaction=decorate,decoration={markings,
mark=at position {\X} with {\path (-1,0.2) -- 
node[midway,below=14pt,draw=red,single arrow,fill=red!20,sloped,transform shape]{increasing}
(1,0.2);
}}] plot [smooth,tension=.7,samples=200] coordinates { 
 (.5,1) (1.25,.5) (2.75,1) (4.5,2.5) (6,1.75) };
\filldraw[black] (1.25,.5) circle (2pt) coordinate (start);
\filldraw[black] (4.5,2.5) circle (2pt) coordinate (end);
\draw (1.25,0) node[below] {$a$} -- (1.25,.5) -- (0,0.5) node 
  [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,2.5) -- (0,2.5) node 
  [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is less than the\\ 
  output for $b$.};
\begin{scope}[xshift=8cm]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [blue,<->,thick,postaction=decorate,decoration={markings,
mark=at position {\X} with {\path (-1,1) --
node[midway,below,draw=blue,single
arrow,fill=blue!20,sloped,transform shape]{decreasing} (1,1);
}}] plot [smooth,tension=.7,samples=200] coordinates { 
  (.5,2.5) (1.25,2.6) (2.75,1) (4.5,.5) (6,1.25)  };
\filldraw[black] (1.25,2.6) circle (2pt) coordinate (start);
\filldraw[black] (4.5,.5) circle (2pt) coordinate (end);
\draw (1.25,0) node[below] {$a$} -- (1.25,2.6) -- (0,2.6) node 
 [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,.5) -- (0,.5) node 
 [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is greater than the\\ 
  output for $b$.};
\end{scope}  
\end{tikzpicture}}
\end{document}

enter image description here

As for the inline animation: I have not much experience with that, but I just used this great answer and it immediately worked. Wish all answers were that clear! (Use acroread to view it.)

\documentclass{article}
\usepackage{animate}
\usepackage{tikz}
\usetikzlibrary{shapes.arrows,decorations.markings}

\begin{document}
\begin{animateinline}[controls,autoplay,loop]{2}
\multiframe{16}{n=1+1}{\begin{tikzpicture}[font=\scriptsize]
\pgfmathsetmacro{\X}{0.175+0.025*\n}
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [red,<->,thick,postaction=decorate,decoration={markings,
mark=at position {\X} with {\path (-1,0.2) -- 
node[midway,below=14pt,draw=red,single arrow,fill=red!20,sloped,transform shape]{increasing}
(1,0.2);
}}] plot [smooth,tension=.7,samples=200] coordinates { 
 (.5,1) (1.25,.5) (2.75,1) (4.5,2.5) (6,1.75) };
\filldraw[black] (1.25,.5) circle (2pt) coordinate (start);
\filldraw[black] (4.5,2.5) circle (2pt) coordinate (end);
\draw (1.25,0) node[below] {$a$} -- (1.25,.5) -- (0,0.5) node 
  [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,2.5) -- (0,2.5) node 
  [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is less than the\\ 
  output for $b$.};
\begin{scope}[xshift=8cm]
\draw[->] (-.5,0)--(6,0) node[below] {$x$};
\draw[->] (0,-.5)--(0,3.5) node[left] {$y$};
\draw [blue,<->,thick,postaction=decorate,decoration={markings,
mark=at position {\X} with {\path (-1,1) --
node[midway,below,draw=blue,single
arrow,fill=blue!20,sloped,transform shape]{decreasing} (1,1);
}}] plot [smooth,tension=.7,samples=200] coordinates { 
  (.5,2.5) (1.25,2.6) (2.75,1) (4.5,.5) (6,1.25)  };
\filldraw[black] (1.25,2.6) circle (2pt) coordinate (start);
\filldraw[black] (4.5,.5) circle (2pt) coordinate (end);
\draw (1.25,0) node[below] {$a$} -- (1.25,2.6) -- (0,2.6) node 
 [left] {$f(a)$};
\draw (4.5,0) node[below] {$b$} -- (4.5,.5) -- (0,.5) node 
 [left] {$f(b)$};
\node at (2.75,-1) [align=left] {If the input $a$ is less than 
  the input $b$,\\ then the output for $a$ is greater than the\\ 
  output for $b$.};
\end{scope}  
\end{tikzpicture}}
\end{animateinline}
\end{document}
  • perfect! I really like the animation! Thanks Marmot. – MathScholar Dec 21 '18 at 03:02
  • I can get this animation by running your program to outputting the pdf for the frames but then only know of a program in beamer where I use the package "animate". Would it be possible to run this an article documentclass? – MathScholar Dec 21 '18 at 23:50
  • maybe you want me to ask in a separate question?! – MathScholar Dec 21 '18 at 23:58
  • @MathScholar I added an inline animation. All I did was to use an answer by AlexG, a user whose posts I really like, and it did work immediately. –  Dec 22 '18 at 01:39
  • again thanks for this. I was looking at AlexG's link and was starting when I saw you posted this. This is a template from which I can work! I write in the article documentclass, so this helps tremendously! – MathScholar Dec 23 '18 at 00:14