1

Below, is some code I'm using on a work.

\documentclass[12pt,a4paper]{book}

\usepackage{graphicx}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{enumitem}

\graphicspath{ {./Pictures} }

\begin{document}

sdlaksdasdkj lasjdlakjsdlajçd çlaksdçlahsd ççajshdaçslkhdçlawhoqiw aosihdq+we+poikjlçaks 

\begin{figure}[h!]
  \centering
  \includegraphics[scale=1]{SizeGraph.png}
  \caption{Plot of size accordingly to the number of replications}
\end{figure}


kçlksdaºlçskdja ºsºçljas daihpoquwhejsdkabjboqu  skjdbascoupreqweoru adpjncopowueyr cnjdpoouhwer ppouweyr hjaspdsaopoih wqpoihpf sdfapougepwqry fdasdfc

\begin{figure}[h!]
  \centering
  \includegraphics[scale=1]{PowerGraph.png}
  \caption{Plot of size accordingly to the number of replications}
\end{figure}


\end{document} 

The problem begins when I use the same code on book tex file, i.e.,

\documentclass[12pt,a4paper]{book}

\usepackage{graphicx}
\usepackage{bm}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{enumitem}
\usepackage{url}
\usepackage{listings,xcolor}

\begin{document}

\frontmatter

%\setcounter{section}{1}

\tableofcontents

\mainmatter

\chapter{Simulations}

\input{simulations.tex}

\appendix

\section{Ehm} 
\input{Ehm.tex}

\backmatter

\begin{thebibliography}{99}

sdasdasçdasçdlkçalskdç

\end{thebibliography}

\end{document}

The simulation.tex file has the same code as the one I wrote at the beginning of this question. However, when I compile, the simulations section doesn't produce the same output, since the text that was supposed to show up between the pictures SizeGraph.png and PowerGraph.png, now appears before the first picture. How can I solve this problem?

Any help would be appreciated.

  • If you do not want to have it floating, just put it in a center environment and use \captionof{figure}{...}. If you want to get help on a specific case, you will have to minimize your code a lot. Just show us the very problem. – LaRiFaRi Jul 8 '15 at 13:37
  • @LaRiFaRi Don't I do that already with \centering? – An old man in the sea. Jul 8 '15 at 13:55
  • Yes, but inside the figure environment, you will get the floating behaviour you are seeing right now. (btw. I am not recommending this. I never use any parameter inside \begin{figure}[] if it is not totally needed) – LaRiFaRi Jul 8 '15 at 14:02
  • @LaRiFaRi then, how would I do what you're suggesting? I'm a beginner in latex... – An old man in the sea. Jul 8 '15 at 14:03
1

If you do not want the figures to float away, just do not use a floating environment like figure. I can not test your case, as I have no real MWE, but I guess that something is pushing your figure to a position, LaTeX sees better fit in.

Below I show you how to get the same result with a center (second figure). This environment does not float.

% arara: pdflatex

\documentclass[12pt,a4paper]{book}
\usepackage[demo]{graphicx}
\graphicspath{ {./Pictures} }
\usepackage{caption}

\begin{document}    
    sdlaksdasdkj lasjdlakjsdlajçd çlaksdçlahsd ççajshdaçslkhdçlawhoqiw aosihdq we poikjlçaks 

    \begin{figure}[h!]
        \centering
        \includegraphics[scale=1]{SizeGraph.png}
        \caption{Plot of size accordingly to the number of replications}
    \end{figure}    

    kçlksdaºlçskdja ºsºçljas daihpoquwhejsdkabjboqu  skjdbascoupreqweoru adpjncopowueyr cnjdpoouhwer ppouweyr hjaspdsaopoih wqpoihpf sdfapougepwqry fdasdfc

    \begin{center} 
        \includegraphics[scale=1]{PowerGraph.png}
        \captionof{figure}{Plot of size accordingly to the number of replications}
    \end{center}    
\end{document}   

enter image description here


Off-topic: mathtools loads amsmath so get rid of the latter.

  • When trying to load \usepackage{caption}, the usual window to download file shows, and after compiling I get : «! LaTeX Error: File `caption.sty' not found.» Do you know why? – An old man in the sea. Jul 8 '15 at 14:25
  • @Anoldmaninthesea. tex.stackexchange.com/q/152277 – LaRiFaRi Jul 8 '15 at 14:29
  • @Anoldmaninthesea you are very welcome. Glad it worked. – LaRiFaRi Jul 8 '15 at 22:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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