3

I am having a problem getting a tikz graph to correctly sit below the a) part of the problem in the solution: My code is as follows:

\documentclass[12pt,leqno]{article}
\usepackage{amsmath, amsfonts, amssymb,amsthm}
\usepackage[margin=1 in]{geometry} %margins
\usepackage{tikz} %Vector Drawing and Graphs
\usepackage{pgfplots}
\newtheorem{exer}{Exercise}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
\renewcommand*{\proofname}{Solution}



\makeatletter\@enumdepth1\makeatother

\begin{document}
\begin{center}
    \textbf{Example Work}
\end{center}

\setcounter{exer}{-1}


\begin{exer}
    $f(x)=2x-1$ \hspace{0.25 in} $1 \leq x \leq 4$
\end{exer}

\begin{proof}
\begin{enumerate}

\item \begin{tikzpicture}
    \begin{axis}
    [axis lines=center, xlabel=$x$, ylabel=$y$, ytick={-3,...,10}, xtick={-3,...,5},xmin=-1, xmax=5, ymin=-1, ymax=8, grid=major, thick]
    \addplot
    [domain=1:4, samples=50, very thick]
    {2*x-1};

    \draw[fill=black] (axis cs:1,1) circle[radius=1.25mm];
    \draw[fill=black] (axis cs: 4,7) circle[radius=1.25mm];

    \end{axis}
    \end{tikzpicture}

\item From the function definition of average rate of change: $m=\frac{f(b)-f(a)}{b-a}=\frac{7-1}{4-1}=\frac{6}{3}=2$
\item From the graph in part \textbf{a)} the range is $1 \leq y \leq 7$.
\end{enumerate}

\end{proof}
\end{document}

The result

1
  • 1
    try \item \ \par\begin{tikzpicture}. By the way may be add \begin{proof}\ \par
    – touhami
    Aug 31, 2015 at 0:25

1 Answer 1

3

You can select the baseline for the tikzpicture; for example, using baseline=(current bounding box.north) as option you get

enter image description here

The code:

\documentclass[12pt,leqno]{article}
\usepackage{amsmath, amsfonts, amssymb,amsthm}
\usepackage[margin=1 in]{geometry} %margins
\usepackage{tikz} %Vector Drawing and Graphs
\usepackage{pgfplots}
\usepackage{enumitem}

\newtheorem{exer}{Exercise}
\newtheorem{theorem}{Theorem}
\newtheorem*{theorem*}{Theorem}
\renewcommand*{\proofname}{Solution}

\begin{document}

\begin{center}
\textbf{Example Work}
\end{center}

%\setcounter{exer}{-1}


\begin{exer}
    $f(x)=2x-1\qquad 1 \leq x \leq 4$
\end{exer}

\begin{proof}
\begin{enumerate}[label=(\alph*)]
\item\label{ite:figure} \begin{tikzpicture}[{baseline=(current bounding box.north)}]
    \begin{axis}
    [axis lines=center, xlabel=$x$, ylabel=$y$, ytick={-3,...,10}, xtick={-3,...,5},xmin=-1, xmax=5, ymin=-1, ymax=8, grid=major, thick]
    \addplot
    [domain=1:4, samples=50, very thick]
    {2*x-1};

    \draw[fill=black] (axis cs:1,1) circle[radius=1.25mm];
    \draw[fill=black] (axis cs: 4,7) circle[radius=1.25mm];

    \end{axis}
    \end{tikzpicture}

\item From the function definition of average rate of change: $m=\frac{f(b)-f(a)}{b-a}=\frac{7-1}{4-1}=\frac{6}{3}=2$
\item From the graph in part~\ref{ite:figure} the range is $1 \leq y \leq 7$\qedhere.
\end{enumerate}
\end{proof}

\end{document}

As side notes, I used the enumitem package to easily produce the required formatting for the enumerate; I used \label, \ref to cross-reference the first part (is never a good idea to manually number elements); I used \qedhere to correct the vertical position of the end-mark.

1
  • @1028 You're welcome! I updated my answer introducing some other improvements to the code; this updated version might be of interest for you. Aug 31, 2015 at 1:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .