[Tex/LaTex] Horizontal and Vertical alignment of images

floatsformattingsubfloats

I'm using the acm latex template for journals available here: http://www.acm.org/publications/authors/submissions

This follows a one-column format. Now I have 8 images, which I want to be displayed with captions in the following pattern:

enter image description here

I don't know how to get this format using subfigure or any other way.

\documentclass[format=acmsmall, review=false, screen=true]{acmart}
\usepackage{subcaption}
\usepackage{array}
\usepackage{varwidth}
\usepackage{lipsum}
\begin{document}
\title[This is a Title]{This is a title}  
\maketitle

\section{Introduction}
\lipsum[2-4]

\begin{center}
\begin{minipage}{0.5\columnwidth}
\includegraphics[width=\linewidth]{pam}
\captionof{figure}{}
\end{minipage}
\end{center}

\begin{center}
\begin{minipage}{0.5\columnwidth}
\includegraphics[width=\linewidth]{jam}
\captionof{figure}{}
\end{minipage}
\end{center}

.
.
.
.

\end{document}

Best Answer

With the subcaption package, a subfigure environment is a minipage environment, with the added capability of processing \caption and \label statements.

enter image description here

\documentclass[format=acmsmall, review=false, 
               screen=true, demo]{acmart}
\usepackage{subcaption}
\usepackage{array,varwidth,lipsum}
\begin{document}
\title{Chow, Dow, and Pow}  
\author{Mr. T and the A-Team}
\date{\today}
\maketitle

\section{Introduction}
\lipsum[2-4] % filler text

\begin{figure}[tp!]
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figa}
\caption{}
\end{subfigure}\hfill
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figb}
\caption{}
\end{subfigure}

\medskip
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figc}
\caption{}
\end{subfigure}\hfill
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figd}
\caption{}
\end{subfigure}

\medskip
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{fige}
\caption{}
\end{subfigure}\hfill
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figf}
\caption{}
\end{subfigure}

\medskip
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figg}
\caption{}
\end{subfigure}\hfill
\begin{subfigure}{0.475\textwidth}
\includegraphics[width=\linewidth]{figh}
\caption{}
\end{subfigure}

\caption{Overall figure caption}
\end{figure}

\lipsum[5-12] % more filler text
\end{document}