中心子图;修复 TikZ 错误

中心子图;修复 TikZ 错误

我正在尝试将 TikZ 生成的一些图形居中。在我的示例中,我有三个大型 Tikz 图片,它们是单独的图形。我也有相同的三张图片,但这次是子图。

所有图形在文档中都不是完全居中(它们可能看起来居中,但略微向左悬垂)。此外,最后一张 Tikz 图片不正确;线条已移位,x 轴标签也已移位。

我怎样才能使所有图形和子图形居中?最后一张 Tikz 图片有什么问题?

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

答案1

\centering你的第二组数字中有一些虚假数字。在最后的 中,删除中的tikzpicture分号。;\draw[thick,->] (-3.5,0) -- (3.5,0);

相关内容