[Tex/LaTex] Subfigures side by side with captions using minipage instead of subfigures

minipagesubfloatsvertical alignment

I tried to insert side by side figures making a minipage instead of subfigures. The captions of the two figures are not aligned and are numbered ina wrong way.

I'd like to align captions and number the figures (a), (b) and the total figure fig. n with n the correct number (1 if the fig is the first in the document ecc).

\documentclass{article}
\usepackage{mwe}

\begin{document}

\begin{figure}[h]
    \centering
    \begin{minipage}{0.45\textwidth}
        \centering
        \includegraphics[scale=0.3]{fig2a}
        \caption{Modello compartimentale mammellare (o mammillare).}
    \end{minipage}\hfill
    \begin{minipage}{0.45\textwidth}
        \centering
        \includegraphics[scale=0.3]{fig2b}
        \caption{Modello compartimentale catenario.}
    \end{minipage}
    \caption{Principali topologie dei modelli compartimentali.}
\end{figure}

\end{document}

enter image description here

Thank you very much in advance.

Best Answer

To repeat what was already stated in the comments: A subfigure environment is already a minipage environment -- just one with some added capabilities related to creating captions.

Here's how I'd rewrite your code, mainly loading the subcaption package and using two subfigure environments.

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx} % omit 'demo' option in real doc.
\usepackage{subcaption}
\usepackage[italian]{babel}

\begin{document}

\begin{figure}
  \begin{subfigure}[t]{0.475\textwidth}
    \includegraphics[width=\textwidth]{fig2a}
    \caption{Modello compartimentale mammellare (o mammillare).}
    \label{fig-a}
  \end{subfigure}\hfill
  \begin{subfigure}[t]{0.475\textwidth}
    \includegraphics[width=\textwidth]{fig2b}
    \caption{Modello compartimentale catenario.}
    \label{fig-b}
  \end{subfigure}
  \caption{Principali topologie dei modelli compartimentali.} 
  \label{fig:main}
\end{figure}

\end{document}