2

This is my original document:

-------------------
|sec 1            |
|-----            |
||fig|            |
|-----            |
|                 |
|                 |
|      page1      |
-------------------

I'm hoping to position the figure to the center of the page, but after adding [p] to \begin{figure}[p], I got 2 pages:

-------------------
|sec 1            |
|                 |
|                 |
|                 |
|                 |
|                 |
|      page1      |
-------------------

-------------------
|                 |
|                 |
|      -----      |
|      |fig|      |
|      -----      |
|                 |
|      page2      |
-------------------

Is it possible to position the image in the center of the page even with other contents, like this?

-------------------
|sec 1            |
|                 |
|      -----      |
|      |fig|      |
|      -----      |
|                 |
|      page1      |
-------------------

Right now let's assume "other content" is simply the section title.

The only solution I have now is to measure the vertical space brought by the section title, and then compensate the same length at the bottom of the page and use two \vfill to center the figure vertically. But can it be done easier?

Code to get started:

\documentclass{article}
\usepackage[demo]{graphicx}
\setlength{\parindent}{0pt}

\begin{document}
\section*{sec 1}
\begin{figure}[p]
\centering
\includegraphics{noimage}
\end{figure}

\end{document}

2
1

You can use tikz for that. I assume you wanted the figure + its caption centred.

\documentclass{article}
\usepackage[demo]{graphicx}
\setlength{\parindent}{0pt}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{capt-of}
\begin{document}
    \section*{sec 1}
    \lipsum[1]
    
    \begin{tikzpicture}[inner sep=0pt, overlay, remember picture]
    \node at (current page.center) {\begin{tikzpicture}
            \node (fig) {\includegraphics{noimage}};
            \node [below=\belowcaptionskip of fig,text width=\linewidth] {\captionof{figure}{Caption}\label{fig}};
        \end{tikzpicture}};
    \end{tikzpicture}
\end{document}

If you want only the picture at page centre, we can remove the second tikzpicture:

\documentclass{article}
\usepackage[demo]{graphicx}
\setlength{\parindent}{0pt}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{capt-of}
\begin{document}
    \section*{sec 1}
    \lipsum[1]
    
    \begin{tikzpicture}[inner sep=0pt, overlay, remember picture]
            \node (fig) at (current page.center) {\includegraphics{noimage}};
            \node [below=\belowcaptionskip of fig,text width=\linewidth] {\captionof{figure}{Caption}\label{fig}};
    \end{tikzpicture}
\end{document}

Edit

For the subfigures, I use a matrix:

\documentclass{article}
\usepackage[demo]{graphicx}
\setlength{\parindent}{0pt}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\usepackage{caption}
\begin{document}
    \section*{sec 1}
    \lipsum[1]
    
    \begin{tikzpicture}[inner sep=0pt, outer sep=0pt, overlay, remember picture]
        \matrix[name=F, matrix of nodes, row sep=1ex, column sep={2em}, nodes={text width=.45\linewidth, anchor=center, align=center}] at (current page.center) {%
            \includegraphics[width=\linewidth]{example-image-a} & \includegraphics[width=\linewidth]{example-image-b}\\
            Subcaption a & Subcaption b\\
            \includegraphics[width=\linewidth]{example-image-c} & \includegraphics[width=\linewidth]{example-image}\\
            Subcaption c & Subcaption d\\
        };
        \node [below =\belowcaptionskip of F, text width=\linewidth] {\captionof{figure}{Caption}\label{fig}};
    \end{tikzpicture}
    
\end{document}

enter image description here

2
  • Can we insert subfigure into figure from tikz? I'm asking because my actual purpose is plotting multiple (4) subfigures into this figure and ideally this figure as a whole centered in a page. – Rahn Feb 5 at 15:58
  • One possibility is to use a matrix. – NBur Feb 5 at 16:50

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.