添加箭头增加和减少 Tikz 图

添加箭头增加和减少 Tikz 图

大家好,我不知道如何将我想要的箭头添加到此图像中。以下是图像/最小示例以及我的目标。我需要帮助添加箭头:

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

输出:

在此处输入图片描述

我正在尝试添加“增加”和“减少”箭头,如下所示:

在此处输入图片描述

答案1

像这样?

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

在此处输入图片描述

当然,您也可以使用下面的箭头。

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

在此处输入图片描述

另一种可能性是使用decorations.markings它,如 pgfmanual 第 587 页所述。

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

在此处输入图片描述

至于内联动画:我对此没有太多经验,但我只是用过这个很好的答案并且立即见效。希望所有答案都如此清晰!(使用 acroread 查看。)

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

相关内容