1

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

Shika93
  • 371

1 Answers1

3

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.

JLDiaz
  • 55,732