TransWikia.com

Locating figure in the center of a page

TeX - LaTeX Asked on December 24, 2020

I use "elsarticle" class and for locating a figure (PDF file) in the center of the page, I use the following code:

begin{figure}label{Fig:7}
centering
{includegraphics[width=17cm,height=20cm,keepaspectratio]{Figs/f}}
caption{Caption.} 
end{figure}

But, unfortunately the figure is not placed in the center and inclines to the right side of the page. Specifically, when the size of the image increases, some part of it becomes hidden in the right side of the page. This is a solution from one of the previous posts but it does not work for me. How it can be corrected?

Update
The solution @Mico suggested produces the following result.

One Answer

If the elsarticle class is loaded with any options, the default width of the text block is 345pt=12.125cm. Insisting on setting width=17cm will get you nothing but a graphic that's 4.875cm too wide. Don't believe me? Consult the log file, where you'll find a warning that some hbox is 138.69684pt too wide. A quick calculation verifies that 138.69684pt=4.875cm.

What to do? Do just what I already suggested in a comment, i.e., replace

includegraphics[width=17cm,height=20cm,keepaspectratio]{Figs/f}

with

includegraphics[width=textwidth,height=0.95textheight,keepaspectratio]{Figs/f}

Why height=0.95textheight rather than, say, height=1textheight? It's because you need to reserve some space for the caption.


A full MWE (minimum working example):

documentclass[demo]{elsarticle} % remove 'demo' option in real document
usepackage{graphicx}
begin{document}
begin{figure}[p]
centering
includegraphics[width=textwidth,
                 height=0.95textheight, % leave space for caption
                 keepaspectratio]%
                {Figs/f}
caption{Caption.}  
label{Fig:7x} % always place label after, not before, caption
end{figure}
end{document}

Answered by Mico on December 24, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP