3

i write this code:

\subsubsection{Aller au calcul}
\begin{figure}[h]
    \centering
    \includegraphics[width=5in]{FG3}
    \caption{Page d'aller au calcul}
\end{figure}
\subsection{Pages de calcul}
\subsubsection{Activités}
\begin{figure}[h]
    \centering
    \includegraphics[width=5in]{FG4}
    \caption{Page d'activités}
\end{figure}

but the resultis not what i expected, i mean the figures are under the two section titles, not each figure is under each title, how i can fix that?

6
  • 3
    It seems you don't want the figures to float. So either don't use figure or package float.
    – cabohah
    Apr 23 at 6:58
  • but if i don't use figure i can't update the figure list?
    – Alia
    Apr 23 at 6:59
  • When using a KOMA-Script class, see also tex.stackexchange.com/a/716272/277964.
    – cabohah
    Apr 23 at 9:12
  • When a figure with [h] move, there is some good reason for this. When a figure with [h!] move, there are not enough space and then also a figure with [H] or an image without figure also will move to the next page, with the difference of leave a ugly gap that is not filled with next text. Tip: never use [H] and use [h] as few as possible. Cross-reference in text a is nice pre-informatic invention to convert the problem of displaced figures in an opportunity to make elegant layouts.
    – Fran
    Apr 23 at 10:15
  • Unless your document's paper size is unusually large, say "A3" or "USLegal", or, conversely, unless the graphs' heights are unusually small, it's quite unlikely that both subsubsection-level headers and both graphs will fit on one and the same page. Instead of specifying the graphs' widths, you may want to think about specifying the graphs' heights if it's really important to place both headers and both graphs on a single page.
    – Mico
    Apr 23 at 11:14

2 Answers 2

3

I suggest you replace [h] with [h!]:

...
\begin{document}   
...
\subsubsection{Aller au calcul}
\begin{figure}[h!]
    \centering
    \includegraphics[width=5in]{FG3}
    \caption{Page d'aller au calcul}
\end{figure}
...
\end{document}

That way, if the graph fits below the subsubsection-level header, LaTeX will place it there. If the graph doesn't fit below this header, LaTeX will place it at the top of the next page; this happens because LaTeX automatically converts [h!] to [ht!] "behind the scenes". If you don't like this and insist that the graph must be placed below the subsubsection-level header, you'll need to replace width=5in with height= xx in, where "xx" should be chosen suitably. Naturally, the less space remains on the page, the smaller "xx" will have to be.

4
  • @Mico the placement H forced to place the float at the exact place, so only I didn't mention about h, is there any thing wrong, please excuse
    – MadyYuvi
    Apr 23 at 9:01
  • 1
    Also, it's my pleasure if you modify suggestion given by mine
    – MadyYuvi
    Apr 23 at 9:19
  • I've gone ahead and edited your answer directly.
    – Mico
    Apr 23 at 11:08
  • Thanks for the edits
    – MadyYuvi
    Apr 23 at 11:31
2

If you are going to put nothing into your subsections except figures, why not put the \subsection inside the figure?

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}

\begin{figure}[ht]
\subsubsection{Aller au calcul}
    \centering
    \includegraphics[width=5in]{example-image-a}
    \caption{Page d'aller au calcul}
\end{figure}

\subsection{Pages de calcul}

\begin{figure}[ht]
\subsubsection{Activités}
    \centering
    \includegraphics[width=5in]{example-image-b}
    \caption{Page d'activités}
\end{figure}

\end{document}
2
  • Note, that now it could happen, that subsubsection “Activités” will float as page top figure above subsection “Pages de calcul” or behind the next section. Just add a \section{Oh, no!} before \end{document} and you'd see, what I mean.
    – cabohah
    Apr 23 at 14:40
  • You could always add a \clearpage before each \section. Then again, the whole premise is somewhat unlikely. Apr 23 at 19:22

Not the answer you're looking for? Browse other questions tagged .