2

How do I put the title "Illustration of two concave functions" under the plots in the following code? I tried using

\node[font=\bfseries, anchor=north, inner sep=0, align=center] at ($(current bounding box.south) +(0,-0.5)$){\mbox{Illustration of two concave functions}};

Complete code:

\documentclass{amsart}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}


\usepackage{mathtools,array}



\begin{document}



\centerline{\Large{\textbf{Concavity and the Second Derivative Test}}} \vskip0.25in


\noindent \textbf{Definition} \vskip1.25mm
\noindent \hspace*{1em}
\begin{minipage}{5.75in}
{\em f is a differentiable function defined on an open interval. f is called \textbf{concave} (\textbf{concave up}) if, and only if, the graph of f lies above all of its tangents, and f is called \textbf{convex} (\textbf{concave down}) if, and only if, the graph of f lies below all of its tangents.}
\end{minipage}
\vskip0.25in




\noindent \hspace*{\fill}
\begin{tikzpicture}
\begin{axis}[name=axis_1, width=2.25in, height=2.75in, clip=false,
    axis lines=middle,
    xmin=-5,xmax=5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)},  xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},  yshift=12.5pt, anchor=south west}
]

\addplot[samples=501, domain=-4.643856:4.643856]  {pow(2,x)} node[right, pos=1, font=\footnotesize]{\makebox[0pt][l]{$y = 2^{x}$}};

%The tangent line through (-1, 1/2) to the graph of $y = 2^{x}$ has a slope of (1/2)ln(2).
%The code used to compute the slope is "ln(2)*pow(2,-1)".
\addplot[samples=2, latex-latex, domain=-5:5] {ln(2)*pow(2,-1)*x + ln(2)*pow(2,-1) + 1/2};

%The tangent line through (3, 8) to the graph of $y = 2^{x}$ has a slope of 8ln(2).
\addplot[samples=2, latex-latex, domain=0.6556:5] {ln(2)*pow(2,3)*x - 3*ln(2)*pow(2,3) + 8};

\end{axis}

\end{tikzpicture}
%
\qquad
%
\begin{tikzpicture}
\begin{axis}[name=axis_2, width=2.25in, height=2.75in, axis on top, clip=false,
    axis lines=middle,
    xmin=-5,xmax=5, domain=-5:5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]

\addplot[samples=501, domain=-5:5] {x^2} node[right, pos=1, font=\footnotesize]{\makebox[0pt][l]{$y=x^{2}$}};

\addplot[samples=2, latex-latex, domain=-5:19/4] {-x - 1/4};

%There is a flaw with pgfplots. So, the domain is narrowed a bit.
\addplot[samples=2, latex-latex, domain={2/3+0.001}:{5}] {6*x - 9};


\end{axis}

\end{tikzpicture}

\end{document}
0

Well, here is another solution (which is inferior to my former one, but it's your document). Put both graphs into a single picture by placing the second one with the at attribute to the right of the first one (note the new option at={(2.5in,0)} for the second axis environment), and then add the \node command for the caption.

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{mathtools,array}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}[name=axis_1, width=2.25in, height=2.75in, clip=false,
    axis lines=middle,
    xmin=-5,xmax=5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)},  xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},  yshift=12.5pt, anchor=south west}
]
\addplot[samples=501, domain=-4.643856:4.643856]  {pow(2,x)} node[right, pos=1, font=\footnotesize]{\makebox[0pt][l]{$y = 2^{x}$}};
\addplot[samples=2, latex-latex, domain=-5:5] {ln(2)*pow(2,-1)*x + ln(2)*pow(2,-1) + 1/2};
\addplot[samples=2, latex-latex, domain=0.6556:5] {ln(2)*pow(2,3)*x - 3*ln(2)*pow(2,3) + 8};
\end{axis}
\begin{axis}[at={(2.5in,0)}, name=axis_2, width=2.25in, height=2.75in, axis on top, clip=false,
    axis lines=middle,
    xmin=-5,xmax=5, domain=-5:5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]
\addplot[samples=501, domain=-5:5] {x^2} node[right, pos=1, font=\footnotesize]{\makebox[0pt][l]{$y=x^{2}$}};
\addplot[samples=2, latex-latex, domain=-5:19/4] {-x - 1/4};
\addplot[samples=2, latex-latex, domain={2/3+0.001}:{5}] {6*x - 9};
\end{axis}
\node[font=\bfseries, anchor=north, inner sep=0, align=center] at
($(current bounding box.south) +(0,-0.5)$){\mbox{Illustration of two
    concave functions}};
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

  • Yes, this second code is what I want. I am also using this code to get familiar with the options of pgfplots. Does at={(2.5in,0)} move the second pgfplots diagram 2.5 inches to the right of the first pgfplots diagram? Is the default centered? – user74973 Aug 22 '16 at 17:27
  • 1
    Yes, exactly, at places the second diagram at the point (2.5in,0), while the first one is at (0,0). See section 4.19.1 of the pgfplots manual. – gernot Aug 22 '16 at 17:41
1

I've rewritten your document a bit (see below). Some explanations first.

To have a caption below the two pictures use a center environment.

\begin{center}
[first picture]
\qquad
[second picture]\\[2ex] % some space
The caption explaining the pictures.
\end{center}

Maybe better, use the caption package; this way you can decide later on to number your figure (by removing the *) and refer to it.

\usepackage{caption}
...
\begin{figure}[h] 
[first picture]
\qquad
[second picture]
\caption*{The caption explaining the pictures.}
\end{figure}

You shouldn't use explicit formatting (\hspace, \vskip etc). Use the predefined commands (and adjust them later on if you want to change the formatting) or define your own environments (like the definition environment).

Use math mode for math symbols like $f$.

For emphasizing a word, use \emph{...}. \textbf is usually considered too much of an emphasis, but if you really want to have it boldface, then write \let\emph\textbf before \begin{document}.

Once you are done with constructing your tikzpicture, you can scale it down to fit the page (\begin{tikzpicture}[scale=0.7]).

In definitions, one usually doesn't use 'if and only if' to equate the defined notion with its definition, but just uses 'if'.

If you have several definitions, it might be useful to number them for easier reference. In this case replace \newtheorem* by \newtheorem (and maybe also rename the environment to definition instead of definition* to indicate this change).

\documentclass{amsart}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\usepackage{mathtools,array}
\usepackage{caption}
\newtheorem*{definition*}{Definition}
\begin{document}
\title{Concavity and the Second Derivative Test}
\maketitle

\begin{definition*}
  Let $f$ be a differentiable function defined on an open interval.
  $f$ is called \emph{concave} (\emph{concave up}) if its graph lies
  above all of its tangents. $f$ is called \emph{convex}
  (\emph{concave down}) if its graph lies below all of its tangents.
\end{definition*}

\begin{figure}[h]
\centering
\begin{tikzpicture}[scale=0.7]
\begin{axis}[name=axis_1, %width=2.25in, height=2.75in, %clip=false,
    axis lines=middle,
    xmin=-5,xmax=5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)},  xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)},  yshift=12.5pt, anchor=south west}
]
\addplot[samples=501, domain=-4.643856:4.643856] {pow(2,x)}
node[right, pos=1, font=\footnotesize]{\makebox[0pt][l]{$y = 2^{x}$}};
%The tangent line through (-1, 1/2) to the graph of $y = 2^{x}$ has a slope of (1/2)ln(2).
%The code used to compute the slope is "ln(2)*pow(2,-1)".
\addplot[samples=2, latex-latex, domain=-5:5] {ln(2)*pow(2,-1)*x + ln(2)*pow(2,-1) + 1/2};
%The tangent line through (3, 8) to the graph of $y = 2^{x}$ has a slope of 8ln(2).
\addplot[samples=2, latex-latex, domain=0.6556:5] {ln(2)*pow(2,3)*x - 3*ln(2)*pow(2,3) + 8};
\end{axis}
\end{tikzpicture}
%
\qquad
%
\begin{tikzpicture}[scale=0.7]
\begin{axis}[name=axis_2, axis on top, %width=2.25in, height=2.75in, clip=false,
    axis lines=middle,
    xmin=-5,xmax=5, domain=-5:5,
    ymin=-5,ymax=25,
    restrict y to domain=-5:25,
    xtick={\empty}, ytick={\empty},
    xlabel=$x$,ylabel=$y$,
    axis line style={latex-latex},
    axis line style={shorten >=-12.5pt, shorten <=-12.5pt},
    xlabel style={at={(ticklabel* cs:1)}, xshift=12.5pt, anchor=north west},
    ylabel style={at={(ticklabel* cs:1)}, yshift=12.5pt, anchor=south west}
]
\addplot[samples=501, domain=-5:5] {x^2} node[right, pos=1,
font=\footnotesize]{\makebox[0pt][l]{$y=x^{2}$}};
\addplot[samples=2, latex-latex, domain=-5:19/4] {-x - 1/4};
%There is a flaw with pgfplots. So, the domain is narrowed a bit.
\addplot[samples=2, latex-latex, domain={2/3+0.001}:{5}] {6*x - 9};
\end{axis}
\end{tikzpicture}
\caption*{Illustration of two concave functions}
\end{figure}
\end{document}

enter image description here

  • I don't want to enumerate the figure. (This is part of a chapter on the Mean Value Theorem, but, right now, it is just for my own class.) To be consistent with the other tikzpicture environments in the file, I want to have "Illustration of two concave functions" as a node command. – user74973 Aug 22 '16 at 16:44
  • I have modified my solution to get rid of the figure numbering. Adding the caption as a node to the tikzpicture (to which one of the two?) doesn't make much sense. The purpose of LaTeX is to supply logical markup such that LaTeX, the documentclass and the style files can take care of a consistent typesetting. This is of particular importance if you want to write a book. – gernot Aug 22 '16 at 17:06

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.