10

This is my code, but my picture is on the left!!! Can anyone share a better code? thanks a lot

\begin{figure}[H]
\centering
\includegraphics[width=25cm,height=25cm,keepaspectratio]{1.eps}
\caption{Aerial view}\label{fig:1}
\end{figure}
Torbjørn T.
  • 206,688
Zay
  • 331
  • 9
    Almost certainly your picture is too wide for the page – Joseph Wright Sep 27 '14 at 07:51
  • when i decrease the size it does not make any difference on the centering..and also @1010011010 removing any of those three keys makes no change in the centering.. hence why i posted this question...:( – Zay Sep 27 '14 at 08:13
  • 3
    If you do \includegraphics[width=\linewidth]{1} the image will become as wide as the text block. If it looks off-center then, it is likely because of white borders in the image file itself. – Torbjørn T. Sep 27 '14 at 08:27
  • if i want my picture to be width and height 15 cm...how do i center it???? this is my main issue..:( – Zay Sep 27 '14 at 08:34
  • 1
    @Zay you haven't given much information, but basically before you can centre it you need to make it fit on the page. You haven't said how big your page is, which makes answering difficult. If the image is wider than the text width you need to make the image smaller, make the page wider, or make the image overlap into the margins, all are possible but you have given no indication which you need. centering is not the issue, it wil centre automatically once it fits – David Carlisle Sep 27 '14 at 09:05
  • @TorbjørnT. What's the difference between \includegraphics[width=\linewidth]and \includegraphics[width=\textwidth]? – Aradnix Sep 27 '14 at 09:07
  • @DavidCarlisle its a thesis my page is A4 i guess...what do you suggest? the code i posted is the only one i used.. – Zay Sep 27 '14 at 09:10
  • 1
    @Aradnix http://tex.stackexchange.com/questions/16942/difference-between-textwidth-linewidth-and-hsize – Torbjørn T. Sep 27 '14 at 09:14
  • @Zay the physical size isn't important (to latex) it is the specified textwidth but even the physical size of A4 is only 21cm so what do you want to do with an image that you have scaled to 25cm wide???? – David Carlisle Sep 27 '14 at 09:15
  • Ah.. i understand this issuee.. But presently i scaled it to 10 cm.. both width and height but still in vain.. – Zay Sep 27 '14 at 09:16
  • 1
    @Zay if you specify 10cm it will centre with the commands you show. As I comment above the only issue in the code you posted is that the image is so wide. Incidentally it's best not to include the .eps extension then it will work with pdflatex as well as latex if you have a pdf version of the image – David Carlisle Sep 27 '14 at 09:18
  • @Zay Why do you insist on using such a large size image on a page which doesn't fit? You mean the vertical or horizontal centering? And if better than once you add a MWE and we stop of suggesting blindly? – Aradnix Sep 27 '14 at 09:23

1 Answers1

11

\centering will not centre anything that is wider than the page (as is the case with an image scaled to 25cm wide) all excess width will stick into the right margin (and TeX will issue overfill box warnings). The code shown will centre the image if it was scaled to a smaller width.

David Carlisle
  • 757,742
  • 7
    Is there any way to center objects wider than page width? – frogatto Nov 08 '15 at 19:39
  • 9
    @HiI'mfrogatto just hide the width for example \makebox[0pt]{\includegraphics{..}} has width 0pt with the image centred in it, so if you centre that, the image will stick into both margins – David Carlisle Nov 08 '15 at 19:41