Graphics, Figures & Tablescentering the graphic

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
azizever83
Posts: 41
Joined: Sun Apr 08, 2012 4:31 pm

centering the graphic

Post by azizever83 »

hello,
this is my first post in the forum. I'm still a begginer in Latex.
the problem is that I'm not able to centre my grphics. they all appear in the very right place, and some time just a little of the graphics appear.
here is the code i'm using to include the figure.

Code: Select all

\hspace*{-3.5in}
\includegraphics[scale=1]{/Project/Cloudservices.jpg}
the hspace i tried from -1.5 to -5.5 and also tried using

Code: Select all

\begin{center}
\includegraphics[scale=1]{Project/Cloudservices.jpg}
\end{center} 
another problem is that the path of the images is shown in the pdf file. how to avoid that?

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

centering the graphic

Post by Stefan Kottwitz »

Hi,

welcome to the board!

The {center} environment is good for horizontal centering. Just in case if you use {figure} environments, within those I would use \centering instead.

The effect, that you see the file path in the output, is very probably caused by spaces in the path or file name. Just avoid spaces there. Or, load the grffile package to fix it:

Code: Select all

\usepackage{grffile}
Stefan
LaTeX.org admin
azizever83
Posts: 41
Joined: Sun Apr 08, 2012 4:31 pm

Re: centering the graphic

Post by azizever83 »

Hello Mr. Stefan,
Thanks for you quick response. ur answer was very helpful. however, another problem i just noticed after that is that the figure is not placed in the same place where i needed. it is not in the same place as it was in the source code. sometimes it becomes inside the paragraphe.
Thanks and sorry if it is easy question am still at the beginning of latex.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

centering the graphic

Post by Stefan Kottwitz »

I guess you use a {figure} environment. (Click on this highlighted word to learn more).

Figures are floating objects, which means that LaTeX places them automatically where they fit best, from a typographically point of view and especially for good page breaks.

Imagine, there's 4 cm space left on the page, but your picture has a height of 4.5 cm. If you would insist on staying at the same position within the text, there would be 4 cm white space, the figure on the next page, then comes the following text. But LaTeX does it better: it let's the figure float to the next page, while the following text already continues to fill the nearly empty page, so there's no 4 cm white space. That's a great feature especially for extensive books with many figures!

If you look at books, you will see, that figures are usually well placed, and they are referred to by figure number from within the text. With LaTeX, that's automatic placement - otherwise, if you do figure placement manually, you have to adjust all figure positions in the document again each time you add or remove text at the beginning - or somewhere.

You can ease figure placement by adding positioning options, allowing as many positions as possible. Try:

Code: Select all

\begin{figure}[htbp]
  \centering
  \includegraphics{filename}
  \caption{caption text}
  \label{fig:label}
\end{figure}
Stefan
LaTeX.org admin
Post Reply