1

I have made a figure using TikZ and I want it to be inside a subsection after a few sentences, as shown in the following:

\newpage
    \section{Modeling}
    \subsection{Modeling Trajectory}
    This subsection's content...
    at this point I will....

\begin{figure}
\begin{center}
    \begin{tikzpicture}
    \draw[thick,->] (0,0) -- (6,0) node[anchor=north west] {x};
    \draw[thick,->] (0,0) -- (0,6) node[anchor=south east] {y};
    \draw[thick,->] (3,3) -- (5,2) node[anchor=north west] {$V_{T}$};
    \draw[thick,->] (3,3) -- (1,4) node[anchor=south west] {$F_{Drag}$};
    \draw[thick,->] (3,3) -- (3,1) node[anchor=north west] {g};
    \draw [dashed] (3,3) -- (6,3);
    \draw (4,3) arc (0:-28:1) node[] at (30:5.3)  {$\gamma_{T}$};
    \end{tikzpicture}
    \caption{Ballistic target geometry}
\end{center}
\end{figure}

However, what I get is that the figure at the top of the page, then the section title and the the subsection title.

The result I needed is:

section title
subsection title
figure

I tried using \floatbarrier but it moves the whole figure to the center of other page.

Thank you.

ksgj1
  • 637
Ben
  • 413

2 Answers2

7

The main issue here is the fact that the default float placement is tbp the h for here if possible has to be added manually. Thus use

\begin{figure}[htbp]

Also both figure and center envs introduce vertical space, so the proper method of centering inside a figure is:

\begin{figure}[htbp]
\centering
 ....
\end{figure}

Also the float packages H option should the avoided as much as possible. People generally use it because they forget how to use the [htbp] options, and they forget that floats should go nearby not HERE

daleif
  • 54,450
1

Use the H option from float package.

\documentclass[a4paper, 12pt]{article}
\usepackage{tikz,float}
\begin{document}
\newpage
\section{Modeling}
\subsection{Modeling Trajectory}
This subsection's content...
at this point I will....

\begin{figure}[H]
    \centering
        \begin{tikzpicture}
        \draw[thick,->] (0,0) -- (6,0) node[anchor=north west] {x};
        \draw[thick,->] (0,0) -- (0,6) node[anchor=south east] {y};
        \draw[thick,->] (3,3) -- (5,2) node[anchor=north west] {$V_{T}$};
        \draw[thick,->] (3,3) -- (1,4) node[anchor=south west] {$F_{Drag}$};
        \draw[thick,->] (3,3) -- (3,1) node[anchor=north west] {g};
        \draw [dashed] (3,3) -- (6,3);
        \draw (4,3) arc (0:-28:1) node[] at (30:5.3)  {$\gamma_{T}$};
        \end{tikzpicture}
        \caption{Ballistic target geometry}
\end{figure}
\end{document}

here!!

ksgj1
  • 637