2

In the code, I want the captions of each image to start with (a), (b), etc. and I want to add borders. But it is coming as a separate figure number. I tried using subfigure, but then all the images in a single column.

First I tried-

\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\begin{multicols}{2}
\includegraphics[width=\linewidth]{countyeffect}
\caption{Random effect due to counties obtained from spline coefficients} 
\label{fig7:a} \par
\includegraphics[width=\linewidth]{statemean}\caption{Mean value of states} 
\label{fig7:b} \par
\end{multicols}
\begin{multicols}{2}
\includegraphics[width=\linewidth]{stateslope} \caption{Effect due to slopes} 
\label{fig7:c} \par
\includegraphics[width=\linewidth]{overalllocation}\caption{Overall location effect due to variation in states and counties} 
\label{fig7:d} \par
\end{multicols}
\caption{Illustration of different kind of location effects}
\end{figure}

\end{document}

source: Multiple figures in a two column latex file

I get the following image-

enter image description here

But when I try

\begin{figure}[H]
\begin{multicols}{2}
\begin{subfigure}{.5\textwidth}
\includegraphics[width=\linewidth]{countyeffect}
\caption{Random effect due to counties obtained from spline coefficients} 
\label{fig7:a}
\includegraphics[width=\linewidth]{statemean}\caption{Mean value of states} 
\label{fig7:b}
\end{subfigure}%
\end{multicols}
\begin{multicols}{2}
\begin{subfigure}{.5\textwidth}
\includegraphics[width=\linewidth]{stateslope} \caption{Effect due to slopes} 
 \label{fig7:c}
 \includegraphics[width=\linewidth]{overalllocation}\caption{Overall location effect due to variation in states and counties} 
  \label{fig7:d}
  \end{subfigure}%
  \end{multicols}
  \caption{Illustration of different kind of location effects}
  \end{figure}

Then the subfigures are starting with (a), (b) etc. but I am getting a single column of all the images. But I want something like following-

enter image description here

Thanks.

1 Answers1

2

Use the subfig or subcaption package, not subfigure (not longer maintained). You do not need the multicol package for a 2x2 layout:

mwe

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\subfloat[\label{fig7:a}][Random effect due to counties 
obtained from spline coefficients]
{\includegraphics[width=.45\linewidth]{example-image}}\hfill
\subfloat[\label{fig7:b}][Mean value of states]
{\includegraphics[width=.45\linewidth]{example-image-a}}\par
\subfloat[\label{fig7:c}][Effect due to slopes]
{\includegraphics[width=.45\linewidth]{example-image-b}}\hfill
\subfloat[\label{fig7:d}][Overall location effect due to variation
in states and counties]
{\includegraphics[width=.45\linewidth]{example-image-c}}
 \caption{Illustration of different kind of location effects}
 \end{figure}
\end{document}

If you want borders, the simplest could be a basic 2x2 tabular:

mwe

subfig version:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}
\begin{document}
\begin{figure}
\centering
\begin{tabular}{|c|c|}
\hline
\subfloat[\label{fig7:a}][Random effect due to counties obtained
from spline coefficients]
{\includegraphics[width=.45\linewidth]{example-image}} &
\subfloat[\label{fig7:b}][Mean value of states]
{\includegraphics[width=.45\linewidth]{example-image-a}}\\\hline
\subfloat[\label{fig7:c}][Effect due to slopes]
{\includegraphics[width=.45\linewidth]{example-image-b}} &
\subfloat[\label{fig7:d}][Overall location effect due to variation
in states and counties]
{\includegraphics[width=.45\linewidth]{example-image-c}}\\\hline
\end{tabular}
 \caption{Illustration of different kind of location effects}
 \end{figure}
\end{document}

subcaption version:

\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
adasd
\begin{figure}
\centering
\begin{tabular}{|c|c|}\hline
\begin{subfigure}[c][5.5cm][c]{.45\linewidth}
\smallskip\includegraphics[width=\linewidth]{example-image}
\caption{Random effect due to counties obtained from 
spline coefficients} 
\vfill\label{fig7:a}\end{subfigure} &
\begin{subfigure}[c][5.5cm][c]{.45\linewidth}
\smallskip\includegraphics[width=\linewidth]{example-image-a}
\caption{Mean value of states} 
\vfill \label{fig7:b}\end{subfigure}\\\hline
\begin{subfigure}[c][5.5cm][c]{.45\linewidth}
\smallskip\includegraphics[width=\linewidth]{example-image-b}
\caption{Effect due to slopes}
\vfill \label{fig7:c} \end{subfigure} & 
\begin{subfigure}[c][5.5cm][c]{.45\linewidth}
\smallskip\includegraphics[width=\linewidth]{example-image-c}
\caption{Overall location effect due to variation in 
states and counties}
\vfill\label{fig7:d}\end{subfigure} \\\hline
 \end{tabular}
\caption{Illustration of different kind of location effects}
\end{figure}
\end{document}
Fran
  • 80,769
  • Thanks a lot @Fran . any way I can add the borders ? – madmathguy Mar 06 '17 at 20:02
  • He likely was using subcaption, the subfigure package doesn't define a subfigure environment, it defines a \subfigure macro. subcaption on the other hand, does define a subfigure environment with the same arguments as a minipage, as you can see in the OPs code. – Torbjørn T. Mar 06 '17 at 20:17
  • @TorbjørnT I did not realize. When I read " I tried using subfigure" ... i just remove all the code of the figure except the captions text to start form the scratch. – Fran Mar 06 '17 at 20:26
  • @madmathguy I edited my answer – Fran Mar 06 '17 at 20:27
  • @Fran, perfect !! exactly this is what I wanted.. – madmathguy Mar 06 '17 at 23:59