使用图形环境为我的 tikzpicture 添加字幕会导致问题

使用图形环境为我的 tikzpicture 添加字幕会导致问题

如果我删除图形环境,此代码可以完美运行。不幸的是,我无法为该图形添加标题。

\begin{center}
\begin{figure}
\begin{tikzpicture}

\begin{scope}[thick,font=\scriptsize]
% Axes:
% Are simply drawn using line with the `->` option to make them arrows:
% The main labels of the axes can be places using `node`s:
\draw [->] (-4.5,0) -- (4.5,0) node [above right]  {$\text{Re}[z]$};
\draw [->] (0,-4.5) -- (0,4.5) node [below right] {$\text{Im}[z]$};

% Axes labels:
% Are drawn using small lines and labeled with `node`s. The placement can be set using options
\iffalse% Single
% If you only want a single label per axis side:
\draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
\draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
\draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
\draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
\else% Multiple
% If you want labels at every unit step:
\foreach \n in {-4,...,-1,1,2,...,4}{%
    \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
    \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
}
\fi
\end{scope}
% Quadrant labels
\draw [] (3,3) node {I};
\draw [] (-3,3) node {II};
\draw [] (-3,-3) node {III};
\draw [] (3,-3) node {IV};

% Draw Phasors
\draw [->, thick, red] (0,0) -- (2,1.73) node [above right] {$z_{1} = 2 + j\sqrt{3}$};
\draw [->, thick, purple] (0,0) -- (-3,1) node [above left] {$z_{2} = -3 + j$};
\draw [->, thick, green] (0,0) -- (-0.707,-0.707) node [below left] {$z_{3} = -\sqrt{2} - j\sqrt{2}$};
\draw [->, thick, blue] (0,0) -- (1.73,-1) node [below right] {$z_{4} = \sqrt{3} - j$};

\end{tikzpicture} 
\caption{}
\end{figure}
\end{center}

答案1

下次添加完整的 MWE 并在环境\centering中添加figure

在此处输入图片描述

代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{mathtools}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}

    \begin{scope}[thick,font=\scriptsize]
    % Axes:
    % Are simply drawn using line with the `->` option to make them arrows:
    % The main labels of the axes can be places using `node`s:
    \draw [->] (-4.5,0) -- (4.5,0) node [above right]  {$\text{Re}[z]$};
    \draw [->] (0,-4.5) -- (0,4.5) node [below right] {$\text{Im}[z]$};

    % Axes labels:
    % Are drawn using small lines and labeled with `node`s. The placement can be set using options
    \iffalse% Single
    % If you only want a single label per axis side:
    \draw (1,-3pt) -- (1,3pt)   node [above] {$1$};
    \draw (-1,-3pt) -- (-1,3pt) node [above] {$-1$};
    \draw (-3pt,1) -- (3pt,1)   node [right] {$i$};
    \draw (-3pt,-1) -- (3pt,-1) node [right] {$-i$};
    \else% Multiple
    % If you want labels at every unit step:
    \foreach \n in {-4,...,-1,1,2,...,4}{%
        \draw (\n,-3pt) -- (\n,3pt)   node [above] {$\n$};
        \draw (-3pt,\n) -- (3pt,\n)   node [right] {$\n i$};
    }
    \fi
    \end{scope}
    % Quadrant labels
    \draw [] (3,3) node {I};
    \draw [] (-3,3) node {II};
    \draw [] (-3,-3) node {III};
    \draw [] (3,-3) node {IV};

    % Draw Phasors
    \draw [->, thick, red] (0,0) -- (2,1.73) node [above right] {$z_{1} = 2 + j\sqrt{3}$};
    \draw [->, thick, purple] (0,0) -- (-3,1) node [above left] {$z_{2} = -3 + j$};
    \draw [->, thick, green] (0,0) -- (-0.707,-0.707) node [below left] {$z_{3} = -\sqrt{2} - j\sqrt{2}$};
    \draw [->, thick, blue] (0,0) -- (1.73,-1) node [below right] {$z_{4} = \sqrt{3} - j$};

    \end{tikzpicture} 
\caption{Caption of this figure}
\end{figure}

\end{document}

相关内容