Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a weird problem, whereby if I make my existing tikz picture a 'figure', it suddenly moves forward, as in, past the paragraph that comes after it in the code.

That is, if the code that makes the figure comes before a paragraph in my editor, then when compiled and viewed as a PDF, the figure jumps forward, past the paragraph. I do not know what is happening, or how to fix it.

My code is:

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

Now, all those problems started when I added the:

   \begin{figure}
    \centering

and

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

Prior to that, I didnt have a problem, but at the same time, I didnt have a figure where I could add a caption.

Appreciate any insights, thanks.

EDIT:

Here is the figure I am trying to center its caption for:

enter image description here

Further more, here are all the packaged I am using:

\usepackage{graphicx}
\usepackage{float}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{tikz}
%\usepackage{fullpage}
\usetikzlibrary{matrix}
\usetikzlibrary{decorations.pathreplacing}
\usepackage{bm}
\usepackage{xspace} 
share|improve this question
    
figure is a floating environment: Its main function is to allow LaTeX to move the figure to optimise page breaks. –  David Carlisle May 16 '13 at 0:22
    
@DavidCarlisle I guess I can live with that.... is there a way to make the caption be truly centered though? Right now it seems to be visually too much to the left... –  TyranaSaur May 16 '13 at 0:24
    
It should be centred, please always post complete (small) document showing all packages used. Impossible to say just from a fragment. –  David Carlisle May 16 '13 at 0:26
    
@DavidCarlisle Sorry, please see my edits. I put up a screen shot of the off-centered caption –  TyranaSaur May 16 '13 at 0:28
1  
sorry it doesn't help in particular it doesnt show the class file and in general it always helps to post a complete document that shows the problem (but someone else can take over: bed time in this part of the world:) –  David Carlisle May 16 '13 at 0:51
show 4 more comments

2 Answers

up vote 3 down vote accepted

As David said in a comment, your figure moves because you are using the floating environment figure whose function is to allow LaTeX to move the figure to optimize page breaks.

Regrading the caption position, seeing the style of the caption in the image, my guess is you are using the IEEEtran document class; in this class, captions are flushleft, but the conference class option can give you centered captions:

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

enter image description here

If you want the figure to appear exactly where you wrote it in the code, don't use a floating environment such as figure. Instead, you can use a minipage and the \captionof command from the capt-of package to provide the caption; a little example (I added some spacing using \medskip; you could also use \bigskip for more spacing):

\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}
share|improve this answer
    
Thanks Gonzalo, yes you are right, I am using the IEEE Transactions Class. Sorry if I did not include it, I did not think it was relevant, I am new to all this. Can you please clarify though, you are still using the IEEE Transactions class obviously, and still managing to center the image correct? –  TyranaSaur May 16 '13 at 14:44
    
Using the conference class takes care of the caption, but it still forces the figure to come 'after' the text I usually have... –  TyranaSaur May 16 '13 at 14:58
    
@TyranaSaur I don't recommend the use of the H modifier from the float package. Kind of busy right now, but in 3 hours I can give you an alternative. –  Gonzalo Medina May 16 '13 at 15:35
    
Thanks Gonzalez, also fyi, I have to use the IEEE Transactions class, no choice in that. :-/ –  TyranaSaur May 16 '13 at 15:45
    
@TyranaSaur I had some time, so I updated my answer with an option to have the figure appear exactly where you declared it. Regarding the document class, my answer uses IEEEtran, but with the conference option so your captions will be centered. Can't you use the conference option? –  Gonzalo Medina May 16 '13 at 15:49
show 5 more comments

If you just want to set the figure to the current location, you can use

\usepackage{float}

With this, you can use

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

It puts the figure at the position and suppresses the floating behavoir

share|improve this answer
    
Ah! This appears to work nicely. It places the figure where I want it. :-) There is still the problem of the caption not being centered though... (I am using the IEEE Transactions Class, and I cannot not use it). –  TyranaSaur May 16 '13 at 15:02
    
@TyranaSaur the issue with the caption not being centered has to do with the IEEE class you are using. It has been answered on the site. I think only conference class will center the caption. –  dustin May 16 '13 at 16:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.