tikz 中的“图形”使图像“向前”移动

tikz 中的“图形”使图像“向前”移动

我有一个奇怪的问题,如果我将现有的 tikz 图片变成“图形”,它会突然向前移动,就像在代码中越过它后面的段落一样。

也就是说,如果制作图形的代码在我的编辑器中位于段落之前,那么在编译并以 PDF 形式查看时,图形会向前跳转,超过段落。我不知道发生了什么,也不知道如何修复它。

我的代码是:

The cow jumped over the moon as shown in this figure:

\begin{figure}
\centering

\begin{tikzpicture}
    % Draw the axes
    \draw [->,black] (\var*-1.5,0) -- (\var*3,0) ;
    \draw [->,black] (0,\var*-1.5) -- (0,\var*3) ;    
\end{tikzpicture}

\caption{Foo axis caption} \label{fig:M1} 
\end{figure}

As can be seen in the anove figure, the cow jumped over the moon

现在,当我添加以下内容时,所有这些问题就开始了:

   \begin{figure}
    \centering

 \caption{Foo axis caption} \label{fig:M1} 
 \end{figure}

在此之前,我没有遇到任何问题,但同时,我也没有可以添加标题的图形。

谢谢您任何的见解,谢谢。

编辑:

以下是我试图将其标题置于中心的图形:

在此处输入图片描述

此外,这里是我正在使用的所有软件包:

\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
%\usepackage{fullpage}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{bm}
\usepackage{xspace} 

答案1

正如 David 在评论中所说,您的图形移动是因为您正在使用浮动环境,figure其功能是允许 LaTeX 移动图形以优化分页符。

重新调整标题位置,查看图像中标题的样式,我猜您正在使用IEEEtran文档类;在这个类中,标题是左对齐的,但是conference类选项可以为您提供居中的标题:

\documentclass[conference]{IEEEtran}
\usepackage{tikz}% just for the example
\usetikzlibrary{decorations.pathreplacing,intersections}
\usepackage{lipsum}% just to generate text for the example

\begin{document}

\lipsum[1-4]
\begin{figure}
\centering
 \begin{tikzpicture}[every node/.append style={font=\scriptsize}]

    % Draw the axes
    \draw [->,black] (-1.5,0) -- (3,0) ;
    \draw [->,black] (0,-1.5) -- (0,3) ;

    % Draw the line
    \path[name path=line,draw,-] (0,0) -- (3,2);

    % Draw the circle
    \path [name path=greencircle,draw,green] (+1.5,0) circle (1.5);
    \path [name path=bluecircle,draw,cyan] (0,1.5) circle (1.5);

% find intersections of line and circles
\path[name intersections={of=line and bluecircle, by={a,b}}];
\path[name intersections={of=line and greencircle, by={c,d}}];

% lines from axes to intersection points
    \draw[dashed,cyan] (0,0|-b) -- (b);
    \draw[dashed,cyan] (b|-0,0) -- (b);
    \draw[dashed,green] (0,0|-c) -- (c);
    \draw[dashed,green] (c|-0,0) -- (c);;
  %  \node[] at (-0.25,1.78){$y$};

     \node[left] at (0,0|-b) {$y_3$};
     \node[below] at (b|-0,0) {$x_3$};

     \node[left] at (0,0|-c) {$y_2$};
     \node[below] at (c|-0,0) {$x_2$};  

   \coordinate (O) at (0,0);
% draw braces
    \draw[decorate,decoration={brace,amplitude=5pt,raise=0.5pt,mirror},yshift=0pt] (O) -- (b) node [midway,yshift=-9pt, xshift =6pt]{$|z_3|$};
    \draw[decorate,decoration={brace,amplitude=5pt,raise=0.5pt},yshift=0pt] (O) -- (c) node [midway,yshift=11pt, xshift =-5pt]{$|z_2|$};

   % \node[] at (2.9,-0.25) {$x$};

    % Draw the angle
    \draw [red] (0,0.3) arc (90:33:0.3);
    \draw[red] (0,0.4)arc(90:33:0.4);
    \node[] at (60:.6)  {$\alpha$};

    % Done
\end{tikzpicture}
\caption{Differential Beamformer Patterns}
\end{figure}
\lipsum[1-3]

\end{document}

在此处输入图片描述

如果您希望图形准确地显示在代码中编写的位置,请不要使用浮动环境,例如figure。相反,您可以使用minipage 和包\captionof中的命令capt-of来提供标题;一个小例子(我使用添加了一些间距\medskip;您也可以使用\bigskip获得更多间距):

\documentclass[conference]{IEEEtran}
\usepackage{tikz}% just for the example
\usetikzlibrary{decorations.pathreplacing,intersections}
\usepackage{lipsum}% just to generate text for the example
\usepackage{capt-of}

\begin{document}

\lipsum[1-2]\par\medskip
\noindent\begin{minipage}{\linewidth}
\centering
 \begin{tikzpicture}[every node/.append style={font=\scriptsize}]

    % Draw the axes
    \draw [->,black] (-1.5,0) -- (3,0) ;
    \draw [->,black] (0,-1.5) -- (0,3) ;

    % Draw the line
    \path[name path=line,draw,-] (0,0) -- (3,2);

    % Draw the circle
    \path [name path=greencircle,draw,green] (+1.5,0) circle (1.5);
    \path [name path=bluecircle,draw,cyan] (0,1.5) circle (1.5);

% find intersections of line and circles
\path[name intersections={of=line and bluecircle, by={a,b}}];
\path[name intersections={of=line and greencircle, by={c,d}}];

% lines from axes to intersection points
    \draw[dashed,cyan] (0,0|-b) -- (b);
    \draw[dashed,cyan] (b|-0,0) -- (b);
    \draw[dashed,green] (0,0|-c) -- (c);
    \draw[dashed,green] (c|-0,0) -- (c);;
  %  \node[] at (-0.25,1.78){$y$};

     \node[left] at (0,0|-b) {$y_3$};
     \node[below] at (b|-0,0) {$x_3$};

     \node[left] at (0,0|-c) {$y_2$};
     \node[below] at (c|-0,0) {$x_2$};  

   \coordinate (O) at (0,0);
% draw braces
    \draw[decorate,decoration={brace,amplitude=5pt,raise=0.5pt,mirror},yshift=0pt] (O) -- (b) node [midway,yshift=-9pt, xshift =6pt]{$|z_3|$};
    \draw[decorate,decoration={brace,amplitude=5pt,raise=0.5pt},yshift=0pt] (O) -- (c) node [midway,yshift=11pt, xshift =-5pt]{$|z_2|$};

   % \node[] at (2.9,-0.25) {$x$};

    % Draw the angle
    \draw [red] (0,0.3) arc (90:33:0.3);
    \draw[red] (0,0.4)arc(90:33:0.4);
    \node[] at (60:.6)  {$\alpha$};

    % Done
\end{tikzpicture}
\captionof{figure}{Differential Beamformer Patterns}
\end{minipage}\par\medskip
\lipsum[1-3]

\end{document}

答案2

如果你只想将图形设置到当前位置,你可以使用

\usepackage{float}

有了这个,你可以使用

\begin{figure}[H]
  \centering
  %image
\end{figure}

它将图形放在位置并抑制浮动行为

相关内容