Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)

share|improve this question
1  
insert \centering after figure –  Herbert Jul 14 '11 at 20:10
1  
Yes, that works. But I want to do this without adding anything to every figure in document. –  Ichibann Jul 14 '11 at 20:11
    
Regarding your 2nd question: Use either the caption or the hypcap package. –  Axel Sommerfeldt Jul 14 '11 at 20:54
    
My example results in a top-aligned float, so you must be doing something different. (And without a minimal example it's hard to tell what exactly you're doing different.) –  lockstep Jul 14 '11 at 21:24
    
caption and hypcap... none of them helped... –  Ichibann Jul 14 '11 at 22:42
show 3 more comments

5 Answers

up vote 20 down vote accepted

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.

share|improve this answer
    
What does draft do? I was told that graphicx is better. How to use draft in graphicx? –  Ichibann Jul 14 '11 at 20:17
    
Also, it centers image at the page as whole. I want only to center vertically. There could be more text or images on the same page. –  Ichibann Jul 14 '11 at 20:20
    
@Ichibann It does not require an input file and shows a bounding box with its name instead, hence you can render the document as is. The usage with graphicx is the same. –  Harold Cavendish Jul 14 '11 at 20:20
1  
draft makes the example compilable even if there is no file a.jpg in one's working directory. ;-) This feature is also part of graphicx. –  lockstep Jul 14 '11 at 20:21
add comment

Add the following to your document preamble:

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

The start of every float construction ends with a macro \@floatboxreset that looks like this (from latex.ltx):

\def \@floatboxreset {%
        \reset@font
        \normalsize
        \@setminipage
}

Executing the above suggestion adds \centering at the end of \@floatboxreset, effectively changing it to

\def \@floatboxreset {%
        \reset@font
        \normalsize
        \@setminipage
        \centering
}

which removes the requirement to specify \centering all the time.

share|improve this answer
add comment

You could redefine the figure environment to include the \centering command:

\let\origfigure\figure
\let\endorigfigure\endfigure

\renewenvironment{figure}[1][tbph]{%
    \origfigure[#1]%
    \centering
}{%
    \endorigfigure
}
share|improve this answer
add comment

If you're using the memoir documentclass, global float adjustment may be set using: \setfloatadjustment{<float>}{<adjustment>}. For example,

\documentclass{memoir}
\setfloatadjustment{figure}{\centering}
\begin{document}
  \begin{figure}  
    \includegraphics{image}
    \caption[LoF caption]{Regular caption}
    \label{fig:image}
  \end{figure}
\end{document}
share|improve this answer
add comment

Another way to center all images, is to use \adjincludegraphics from the adjustbox package and declare the center to be used for all of them after any local options. However, this will add center also to all other \adjustbox macros and adjustbox environments. I actually just like to show the principle:

\documentclass{article}

\usepackage{lipsum}% for fummy text only
\usepackage[draft]{graphicx}% remove 'draft' for a real document
\usepackage{adjustbox}
\adjustboxset*{center}
\begin{document}

\lipsum[1]

\begin{figure}
\adjincludegraphics[width=5cm]{a.jpg}
\caption[Long caption]{Caption}
\label{pic-a}
\end{figure}

\lipsum[2]

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

\lipsum[3]

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


\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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