Graphics, Figures & TablesMy figures are not centered

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
argan
Posts: 18
Joined: Thu May 05, 2011 10:46 am

My figures are not centered

Post by argan »

Hi, all.

I'm relatively new to LaTeX, but I couldn't find any information regarding this specific problem (related ones here on the forum, but they didn't help me). My problem is that my figures all become right-aligned, despite having used \centering in the figure environment. Are there any specific packages I should load?

This is the beginning of the document:

Code: Select all

\documentclass[a4paper,11pt]{article}
% define the title
\author{B.~Fallqvist}
\title{Cell mechanics - A litterature study}
\usepackage{graphicx, float}
\begin{document}
% generates the title
\maketitle
% insert the table of contents
\newpage
\tableofcontents
\newpage

Typically, I write a figure as

Code: Select all

\begin{figure}[H]
	\centering
	\includegraphics[scale=0.5, angle=-90]{Figures/focal_adhesion}
	\vspace{1.5cm}
	\caption{Formation of focal adhesions \cite{geiger_09}.}
	\label{focal_adhesion}
\end{figure}
Is there anything in here that makes the figure become right-aligned?

Thanks
Björn

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

My figures are not centered

Post by coachbennett1981 »

When you use the code:

Code: Select all


\begin{figure}{H}
\centering
Make the H lowercase, h. LaTeX is case sensitive with some of the code (or maybe all of the code). Try that. If that doesn't work you can try:

Code: Select all

\begin{center}

\begin{figure}
\includegraphics{...}
\end{figure}

\end{center}

To make things flushright, you can use \begin{flusright}..\end{flushright)
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: My figures are not centered

Post by Stefan Kottwitz »

Hi Björn,

welcome to the board!

Could it be, that your figures are a bit too large? Perhaps just try again but make one smaller for testing, such as scale=0.2.

Do you get any warnings, such as regarding overfull \hbox?

Stefan
LaTeX.org admin
argan
Posts: 18
Joined: Thu May 05, 2011 10:46 am

Re: My figures are not centered

Post by argan »

Hi, and thanks for the welcome.

I've tried both reducing the size of the image, and using h instead of H, but the image is still aligned to the right. It's not as far right as it can be, it looks more just displaced to the right. I'm attaching what it typically looks like. I don't get any error or warnings either. I do get "Bad boxes", though. What does this mean?

Thanks
Attachments
ex.png
ex.png (101.02 KiB) Viewed 14016 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: My figures are not centered

Post by Stefan Kottwitz »

Bad boxes mean something is too large. Did you try to reduce the size of the image more than just a bit? I mean, is it centered if it has only half of the width? I still guess it's too big, so it's overlapping into the marging producing a bad box.

Stefan
LaTeX.org admin
argan
Posts: 18
Joined: Thu May 05, 2011 10:46 am

Re: My figures are not centered

Post by argan »

Yes, I reduced it to very small sizes and tried also, but it didn't help (scales of about 0.1, 0.05 and so on; in the attached image it is 0.5).

I also tried using pstricks with some code a friend sent, but when I load that package, the document doesn't compile at all. Or...it does compile, but any changes I make to it are void.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

My figures are not centered

Post by Stefan Kottwitz »

argan wrote:Yes, I reduced it to very small sizes and tried also, but it didn't help (scales of about 0.1, 0.05 and so on; in the attached image it is 0.5).
So even such a small image is right aligned and overlaps into the right margin?

If yes, please make a compilable small example which can be tested. The code snippets above seem to be ok.

Btw. it would be great if you use code markup to make the code readable. I just did this for you and edited the first post. When you write a post, there's a Code button right above the edit field.

Stefan
LaTeX.org admin
argan
Posts: 18
Joined: Thu May 05, 2011 10:46 am

Re: My figures are not centered

Post by argan »

Hi, Stefan

After lots of tweaking, it seems that the problem is with my .eps-files. I will need to find a new way to create them since the freeware I used to create them distorted them somehow. Sorry to have wasted your time.

Thanks anyway!

Björn
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: My figures are not centered

Post by Stefan Kottwitz »

Hi Björn,

there are tools to fix eps files, for instance the bounding box, such as epstool or ps2eps.

Or you could convert them to pdf, by epstopdf, and use pdfLaTeX with all its advantages such as jpeg/png/pdf support and microtypographic optimization.

It's very good that you found it. It would be great if you mark the question as solved then. Just edit your first post in this thread (the question) and choose the checkmark symbol as topic icon.

Stefan
LaTeX.org admin
Post Reply