[Tex/LaTex] Subfigure without using caption packages

floatssubfloats

I'd like to create a figure consisting of two subfigures without using the caption or subcaption package since these two packages seem to destroy my template. But all the solutions for subfigures I could find in the Internet use these two packages. What other possibilities do I have? I want the two figures in a 2-column layout to cover both columns and each figure should be 1 column width.

Best Answer

Using minipages and a new counter you can produce your subfigures without any packages at all; you can also define a command to provide subcaptions:

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{chngcntr}

\newcounter{mysfig}
\counterwithin{mysfig}{figure}

\renewcommand\themysfig{\thefigure(\alph{mysfig})}
\makeatletter
\newcommand\Scaption[1]{%
\refstepcounter{mysfig}%
\vskip.5\abovecaptionskip
  \sbox\@tempboxa{\small\themysfig~#1}%
  \ifdim \wd\@tempboxa >\hsize
    \small\themysfig~#1\par
  \else
    \global \@minipagefalse
    \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}%
  \fi
  \vskip\belowcaptionskip}
\makeatother

\begin{document}
\lipsum[1-2]
\begin{figure*}
\stepcounter{figure}
\begin{minipage}[t]{\columnwidth}
\begin{minipage}[b]{\columnwidth}
\includegraphics[width=\linewidth]{example-image-a}\par
\end{minipage}
\Scaption{this is the caption for the left subfigure}
\label{sfig:testa}
\end{minipage}\hfill
\begin{minipage}[t]{\columnwidth}
\begin{minipage}[b]{\columnwidth}
\includegraphics[width=\linewidth]{example-image-b}
\end{minipage}
\Scaption{this is the caption for the right subfigure, spanning two lines}
\label{sfig:testb}
\end{minipage}%
\end{figure*}
\lipsum[1-5]
References to subfigures~\ref{sfig:testa} and~\ref{sfig:testb}

\end{document}

enter image description here