0

I have a few pages with two images. I want these images centered on the page. I tried with this

\newpage \vspace*{\fill} 
\begin{figure}[H] \centering
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.8\textwidth, keepaspectratio]{figure/...}}
    \hspace{2mm}
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.8\textwidth, keepaspectratio]{figure/...}}
    \caption[Short-Text]{Long-Text}
\end{figure}
\vspace*{\fill} \newpage

but I don't like the result. There isn't the same space above and below the image. The document class I'm using is book

  • 1
    Perhaps the image is centered in the text area, as opposed to the page. The text area is the page minus the margins, footnote area, headings area, etc. If you want full control over the page coordinates you can use tikz to put the image inside a node with absolute coordinates. – JLDiaz Jun 27 '16 at 16:45
  • Is not centered in text area. Each image has his own page – Shika93 Jun 27 '16 at 16:48
  • It is because of height of \caption and text in \subfloat Possibly related: Height of figure + caption textheight – Runar Jun 27 '16 at 17:01
  • There is nothing like\begin{center}? Is there just one way to do that? – Shika93 Jun 27 '16 at 17:26
2

Here is a minimal example which compares your approach (the vertical fills, which are ok IMHO) with the approach I proposed in a comment (to put it all inside a tikz node which is drawn at the absolute center of the page).

\documentclass{article}
%\usepackage[showframe]{geometry} % uncomment to see the margins
\usepackage{mwe}
\usepackage{float}
\usepackage{subfig}
\usepackage{tikz}

\begin{document}

% Your approach (enclose in vertical fills)
\newpage \vspace*{\fill} 
\begin{figure}[H] \centering
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.7\textwidth, keepaspectratio]{example-image-a}}
    \hspace{2mm}
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.7\textwidth, keepaspectratio]{example-image-b}}
    \caption[Short-Text]{Long-text}
\end{figure}
\vspace*{\fill} \newpage

% My proposed approach (use a tikz node to put it in the absolute center of the page)
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=center, text width=\textwidth, align=justify] at (current page.center) {
\begin{figure}[H]\centering
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.7\textwidth, keepaspectratio]{example-image-a}}
    \hspace{2mm}
    \subfloat[Text]
    {\includegraphics[height=18cm, width=0.7\textwidth, keepaspectratio]{example-image-b}}
    \caption[Short-Text]{Long-text}
\end{figure}
};
\end{tikzpicture}
\newpage
\end{document}

The difference in the output is minimal. You have to compile twice to allow TikZ to place properly the overlay node:

Result

The one on the right (which uses TikZ) appears to be a bit raised but, as said, the difference is minimal. Perhaps in your actual use case it is more visible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.