3

I am writing a thesis and I would like to add an image in a specific place in a chapter.

  \begin{figure}
  \begin{center}
    \includegraphics[scale=0.7]{MC}
    \caption[Diagram.]{\label{mc_label}Diagram.}
  \end{center}
  \end{figure}

Generally the code above works, but the problem is that the compiler adds this image at place, "where he wants to add it" (I think it is associated with the formatting), not at that place, where I would like to add it. I was looking for the solution in the Internet and I founded that I can add something like this:

  \begin{figure}[!h]
  \begin{center}
    \includegraphics[scale=0.7]{MC}
    \caption[Diagram.]{\label{mc_label}Diagram.}
  \end{center}
  \end{figure}

"[!h]" -> I thought that it should work, but it didn't. Thanks for help.

This is the template, which I am using:

https://drive.google.com/file/d/0BwyOySLlDTB_a3R5aFZQNzVFRG8/edit?usp=sharing

Thanos
  • 12,446
Dawid
  • 133
  • 1
    Omit the figure environment, and use the command \captionof{figure}{...} instead of \caption{...}. You need the \usepackage{caption} in your preamble. This prevents floating figures. It will however be shifted to the next page anyway, if there's too few space on the current one –  Aug 17 '14 at 10:19
  • In general, you should help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Aug 17 '14 at 10:21

1 Answers1

2

I use tikz for this sort of thing. It allows you to precisely control where the image appears. As an example, the "chapter heading"

enter image description here

was produced by:

\documentclass{book}   
\usepackage{mwe}% needed only for this example
\usepackage{tikz}% mandatory for the \chapterImage command

\newcommand\chapterImage[2][]{
  \begin{tikzpicture}[overlay,
        picture/.style={anchor=north east,rectangle,inner sep=0pt,outer sep=0pt}]
     \node[picture] at (\textwidth,9cm){\includegraphics[#1]{#2}};
  \end{tikzpicture}
}

\begin{document}

\chapter{An exiting day}
\chapterImage[width=5cm]{example-image-a}
\blindtext

\chapter{An exiting night}
\chapterImage[width=5cm]{example-image-b}
\blindtext

\end{document}

The \chapterImage command above should be used exactly like the \includegraphics command that is embedded inside this macro. That is, the syntax is

\chapterImage[optional arguments for \includegraphics]{name of image file}