[Tex/LaTex] How to automatically center an image

floatshorizontal alignment

I use:

\documentclss{mwrep}
...
\begin{figure}  
\includegraphics{a.jpg}
\caption[Long caption]{Caption}
\label{pic-a}
\end{figure}

How can I make images to be always visible on the center of page? (To be more specific: the center of the image should be between the left and right margin – I use different left and right margins).
I don't want to put anything after every \begin{figure} in my document.

Important: I don't want to waste an entire page on a single image at the very center of the page. I want only horizontal alignment. (left <-> right)

Best Answer

With regard to your first question: Use the floatrow package -- it centers the content of floats by default.

\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{floatrow}

\begin{document}

The first paragraph.

\begin{figure}  
\includegraphics{a.jpg}
\caption[Long caption]{Caption}
\label{pic-a}
\end{figure}

And the second.

\end{document}

If you don't want to load floatrow for whatever reason, you may instead add the following to your preamble (thanks to egreg for the tip):

\makeatletter
\g@addto@macro\@floatboxreset\centering
\makeatother

EDIT: The figure in my example only was vertically centered because I had not added any dummy text. Example corrected.

Related Question