[Tex/LaTex] Arrange four images with letter captions and vertical/horizontal separators

graphicspositioningsubfloats

I would like to arrange four images in a similar style to this code taken slightly modified from Four Arranged Figures are offset .

\documentclass{article}
\usepackage[demo]{graphicx} % leave off demo option in real program
\renewcommand{\thefigure}{\alph{figure}}
\begin{document}


\begin{figure}    
\begin{minipage}[t]{0.5\textwidth}
\includegraphics[width=\linewidth]{a.pdf}
\caption{a)}
\label{fig:immediate}
\end{minipage}

\begin{minipage}[t]{0.5\textwidth}
\includegraphics[width=\linewidth]{b.pdf}
\caption{b)}
\label{fig:proximal}
\end{minipage}


\begin{minipage}[t]{0.5\textwidth}
\includegraphics[width=\linewidth]{c.pdf}
\caption{c)}
\label{fig:distal}
\end{minipage}

\begin{minipage}[t]{0.5\textwidth}
\includegraphics[width=\linewidth]{d.pdf}
\caption{d)}
\label{fig:combined}
\end{minipage}

\end{figure}
\end{document}

My images are mostly white so I would like them to touch but to add a vertical and horizontal line in a cross shape to separate them. The two lines should cross in the middle and stretch to the top and bottom and left and right of the images respectively.

Best Answer

We can achieve this by using subcaption.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption}
\begin{document}


\begin{figure}
  \subcaptionbox{caption}{\includegraphics[width = 2in]{a}}\quad
  \subcaptionbox{caption}{\includegraphics[width = 2in]{b}}\\
  \subcaptionbox{caption}{\includegraphics[width = 2in]{a}}\quad
  \subcaptionbox{caption}{\includegraphics[width = 2in]{b}}
\end{figure}
\end{document}

enter image description here


If you want to caption the 4 subfigures, add \caption{caption} below the lase \subcaptionbox. This will then call this figure 1: caption

enter image description here


To separate the figures with a line, we can use the tabular environment.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subcaption, tabu}
\begin{document}
\begin{figure}
  \begin{tabular}{c|c} %vertical line I added | between cc
  \subcaptionbox{caption}{\includegraphics[width = 2in]{a}}&
  \subcaptionbox{caption}{\includegraphics[width = 2in]{b}}\\
  \hline
  \subcaptionbox{caption}{\includegraphics[width = 2in]{a}}&
  \subcaptionbox{caption}{\includegraphics[width = 2in]{b}}
  \end{tabular}
  %\caption{caption} %this is the caption for the whole figure delete % in front of caption if you want it.
\end{figure}
\end{document}

enter image description here

At present, the demo graphic butts up against the bounding box, but since you figures are mostly white, as you stated, the line should be seen without blending into the picture as with the demo.