# The figure goes to right by default

When I include a figure in my paper, although it doesn't have any extra white borders around it, it goes to the right even when I use \centering. I always have to manually bring it back by \hspace{-1cm}. Here is my code,

\documentclass[conference]{IEEEtran}
\usepackage{algorithm, algpseudocode, dsfont, color, soul, tikz, amsmath, amssymb, amsfonts, amsthm, bbm, bbold, fixmath, mathtools, multirow, boldline, xcolor, colortbl, url, footnote, cite}
\begin{document}
\begin{figure}
\hspace{-1cm}
\includegraphics[scale=.73]{RWD.pdf}
\caption{Picture}
\label{fig: RWD}
\end{figure}
\end{document}


Also I wonder if you tell what is the difference between \hfil and \hfill and between \hspace and \hspace*.

• Don't use scale, but something like width=\columnwidth; your picture is probably too wide when scaled at 73%. – egreg Apr 27 '18 at 9:52
• What's the natural width of RWD.pdf? Is it greater than (1/0.73)\columnwidth? – Mico Apr 27 '18 at 10:22
• \hspace{\fil} and \hspace{\fill} are the same as \hfil and \hfill, resp. \hspace* inserts whitespace no matter what, whereas \hspace might not insert whitespace in case it's part of a "horizontal leader". Apologies for this TeXnical jargon! If you don't know what this means, don't worry about it. – Mico Apr 27 '18 at 10:44

## 1 Answer

Don't use the \hspace{-1cm} directive, don't use the scale=... option when executing \includegraphics. Instead, as already suggested by @egreg in a comment, set the width of the graph to \columnwidth.

You appear to be loading quite a few packages. However, some packages (such as fixmath) shouldn't be loaded at all, at least not for a document that doesn't employ the Computer Modern font family. Other packages needn't be loaded explicitly as they're loaded automatically by other packages. Oh, and do ask yourself if you really need to load these packages. A good rule of thumb is that if you have no idea what a package does, you may not need to load it in the first place...

\documentclass[conference,demo]{IEEEtran} % omit 'demo' option in real doc.
\usepackage[table]{xcolor}
\usepackage[hyphens]{url}
\usepackage{algorithm, algpseudocode, dsfont,
%color, % don't load this since you're loading 'xcolor' as well
soul, tikz,
%amsmath, % is loaded automatically by mathtools package
amssymb,
%amsfonts, % is loaded automatically by 'amssymb' package
amsthm, bbm, bbold,
%fixmath, % don't load this package since Times Roman font is in use
mathtools, multirow, boldline,
%url, % don't load 'url' without the 'hyphens' option
%xcolor, colortbl, % don't load these two packages independently
footnote, % was last updated in 1997! do you really need it?!
cite}
\usepackage{lipsum} % source of filler text

\begin{document}
\lipsum[1] % filler text
\begin{figure}[h!] % "[h!]" used just for this example
%\hspace{-1cm}  % don't use this!
\includegraphics[width=\columnwidth]{RWD}
\caption{Picture}
\label{fig:RWD} % default exension is ".pdf"
\end{figure}
\lipsum[2] % more filler text
\end{document}