Loading images disaligns document

I do not know whether the question has already been asked,

Since I'm a rookie writing in latex, I'd like to know what I'm missing when i upload an image on my document, because it disaligns completely all the text,

The image is uploaded with the following :

\centering\includegraphics[width=0.3\textwidth]{Nameoftheimage}

I'm gonna link two pictures to make myself more clear.

The package used are :

\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{commath}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=1.5}
\usepackage{hyperref}
\usepackage{ragged2e}
\usepackage{titlesec}
\usepackage{mathtools}
\setcounter{secnumdepth}{4}
\usepackage[left=1.3in]{geometry}

before

after

• unrelated comments on your package list, you don't need amsmath if you load mathtools, hyperref should usually be loaded last, don't use blindtext in a real document, I would rather strongly suggest not using commath – David Carlisle Aug 14 at 16:17
• Why? Are there influences between each other? – jacopoburelli Aug 14 at 16:20
• mathtools loads amsmath, so no need to specify it, hyperref has to change lots of things to enable linking so is best loaded last, blindtext is just for generating nosense text examples, and commath is what it is... – David Carlisle Aug 14 at 17:21

1 Answer

\centering\includegraphics{..}

applies \centering to the rest of the document, use

\begin{center}
\includegraphics{...}
\end{center}
• Do be aware that this adds vertical space above and below the inserted graphic. If you want to avoid this space, an alternative formulation is \begingroup \centering ... \endgroup. – barbara beeton Aug 14 at 20:50
• @barbarabeeton with a \par or blank line before the endgroup, yes I decided not to mention that possibility, a non-floating image normally benefits from the vertical offset in anycase – David Carlisle Aug 14 at 20:54
• Of course, you're correct about the \par. If the following text doesn't start a new paragraph, it would even be possible to treat it as an unnumbered equation -- $...$ -- which would get some extra space above and below, though usually not as much as added by center. – barbara beeton Aug 14 at 21:00