4

I am trying to center some figures produced by TikZ. In my example, I have three large Tikz pictures that are separate figures. I also have the same three pictures, but this time as subfigures.

All figures are not exactly centered in the document (they might appear to be centered, but they're slightly hanging left). Also, the very last Tikz picture is not correct; lines have been shifted, as has the x-axis label.

How can I center all figures and subfigures? What is wrong with the last Tikz picture?

\documentclass[11pt]{article}

\usepackage{amsmath,amssymb,amsfonts}
\usepackage{color}
\usepackage{amsthm,array}
\usepackage[center, labelfont=bf]{caption}
\usepackage[justification=centering, labelfont=bf]{subcaption}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,arrows,through}
\RequirePackage{latexsym, verbatim, xspace, setspace}
\RequirePackage{tikz, pgflibraryplotmarks}

\setlength\parindent{0.0in}

\frenchspacing

\begin{document}
\title{Title}
\author{Author}
\date{Date}
\maketitle

\lipsum

\begin{figure}
\centering
% SLOPE FIELD 1
\begin{minipage}[t]{0.45\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.8]
    % t-axis
    \draw[thick,->] (-3.5,0) -- (3.5,0)
    node[above] {$t$}; 
    % x-axis
    \draw[thick, ->] (0,-3.5) -- (0,3.5) 
    node[right] {$x$};
    % segments
    \foreach \t in {-3,-2,-1,0,1,2,3}{
    \foreach \x in {-3,-2,-1,0,1,2,3}{
        \draw[-, thick, color=blue] (\t,\x) -- ++({atan(\t/2)}:0.3);
        \draw[-, thick, color=blue] (\t,\x) -- ++({180+atan(\t/2)}:0.3);
        }}
    \end{tikzpicture}
\caption{$\displaystyle \frac{dx}{dt} = \frac{t}{2}$}
\end{minipage}
\quad
% SLOPE FIELD 2
\begin{minipage}[t]{0.45\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.8]
% t-axis
    \draw[thick,->] (-3.5,0) -- (3.5,0)
    node[above] {$t$}; 
% y-axis
    \draw[thick, ->] (0,-3.5) -- (0,3.5) 
    node[right] {$y$};
% segments
    \foreach \t in {-3,-2,-1,0,1,2,3}{
    \foreach \y in {-3,-2,-1,0,1,2,3}{
    \draw[-, thick, color=blue] (\t,\y) -- ++({atan(1+\y)}:0.3);
    \draw[-, thick, color=blue] (\t,\y) -- ++({180+atan(1+\y)}:0.3);
        }}
    \end{tikzpicture}
\caption{$\displaystyle \frac{dy}{dt} = y+1$}
\end{minipage}\\
\vspace{1cm}
% SLOPE FIELD 3
\begin{minipage}[t]{1.0\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.8]
% Draw x-axis
    \draw[thick,->] (-3.5,0) -- (3.5,0)
        node[above] {$x$}; 
% Draw y-axis
     \draw[thick, ->] (0,-3.5) -- (0,3.5) 
      node[right] {$y$};
    % Draw segments
        \foreach \x in {-3,-2,-1,0,1,2,3}{
        \foreach \y in {-3,-2,-1,0,1,2,3}{
            \draw[-, thick, color=blue] (\x,\y) -- ++({atan(\x+\y)}:0.3);
            \draw[-, thick, color=blue] (\x,\y) -- ++({180+atan(\x+\y)}:0.3);
        }}
    \end{tikzpicture}
\caption{$\displaystyle \frac{dy}{dx} = x+y$}
\end{minipage}
\end{figure}

\begin{figure}
% SLOPE FIELD 1
\centering
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.35]
    % t-axis
        \draw[thick,->] (-3.5,0) -- (3.5,0)
        node[above] {$t$}; 
    % x-axis
        \draw[thick, ->] (0,-3.5) -- (0,3.5) 
        node[right] {$x$};
    % segments
        \foreach \t in {-3,-2,-1,0,1,2,3}{
        \foreach \x in {-3,-2,-1,0,1,2,3}{
            \draw[-, thick, color=blue] (\t,\x) -- ++({atan(\t/2)}:0.3);
            \draw[-, thick, color=blue] (\t,\x) -- ++({180+atan(\t/2)}:0.3);
        }}
    \end{tikzpicture}
\subcaption{$\dfrac{dx}{dt} = \dfrac{t}{2}$}%\label{fig:1a}
\end{minipage}
\quad
% SLOPE FIELD 2
    \centering
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.35]
    % t-axis
        \draw[thick,->] (-3.5,0) -- (3.5,0)
        node[above] {$t$}; 
    % y-axis
        \draw[thick, ->] (0,-3.5) -- (0,3.5) 
        node[right] {$y$};
    % segments
        \foreach \t in {-3,-2,-1,0,1,2,3}{
        \foreach \y in {-3,-2,-1,0,1,2,3}{
            \draw[-, thick, color=blue] (\t,\y) -- ++({atan(1+\y)}:0.3);
            \draw[-, thick, color=blue] (\t,\y) -- ++({180+atan(1+\y)}:0.3);
        }}
    \end{tikzpicture}
\subcaption{$\dfrac{dy}{dt} = y+1$}%\label{fig:1b}
\end{minipage}
\quad
% SLOPE FIELD 3
\centering
\begin{minipage}[t]{0.3\textwidth}
    \centering
    \begin{tikzpicture}[>=latex,scale=0.35]
    % x-axis
    \draw[thick,->] (-3.5,0) -- (3.5,0);
    node[above] {$x$}; 
% y-axis
    \draw[thick, ->] (0,-3.5) -- (0,3.5) 
    node[right] {$y$};
% segments
        \foreach \x in {-3,-2,-1,0,1,2,3}{
        \foreach \y in {-3,-2,-1,0,1,2,3}{
            \draw[-, thick, color=blue] (\x,\y) -- ++({atan(\x+\y)}:0.3);
            \draw[-, thick, color=blue] (\x,\y) -- ++({180+atan(\x+\y)}:0.3);
        }}
    \end{tikzpicture}
\subcaption{$\dfrac{dy}{dx} = x+y$}%\label{fig:1c}
\end{minipage}
\caption{Problem 3.}
\end{figure}

\lipsum

\end{document}
0
2

There were some spurious \centering in your second set of figures. In the last tikzpicture, remove the semicolon ; from \draw[thick,->] (-3.5,0) -- (3.5,0);.

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.