將圖形定位在頁面中央

將圖形定位在頁面中央

我使用“elsarticle”類,為了在頁面中心定位圖形(PDF 文件),我使用以下程式碼:

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

但是,不幸的是,該圖形沒有放置在中間,而是向頁面右側傾斜。具體來說,當圖像尺寸增加時,圖像的某些部分會隱藏在頁面的右側。這是之前一篇文章中的解決方案,但它對我不起作用。如何糾正?

更新 @Mico 建議的解決方案產生以下結果。

答案1

如果elsarticle該類別載入了任何選項,則文字區塊的預設寬度為 345pt=12.125cm。堅持設定width=17cm只會得到一個 4.875 公分太寬的圖形。不相信我?查看日誌文件,您會在其中找到一條警告,指出某些 \hbox138.69684pt太寬。快速計算驗證了這一點138.69684pt=4.875cm

怎麼辦?做我已經在評論中建議的事情,即替換

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

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

為什麼height=0.95\textheight而不是說height=1\textheight?這是因為你需要為標題預留一些空間。


完整的 MWE(最小工作範例):

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

相關內容