[Tex/LaTex] Caption in figure and cross-reference them properly

cross-referencing

I want to know how should I cross-reference the following caption in manuscript in following way Fig 1a and Fig 1b.

\begin{figure}
\minipage{0.50\textwidth}
\includegraphics[width=\textwidth]{fig1}
\endminipage\hfill
\minipage{0.50\textwidth}
\includegraphics[width=\textwidth]{fig2}
\endminipage\hfill

 \caption{$(a)$ taghyer jabejaei: $R$ is the reference configuration and $D$ is the deformed configuration and $(b)$ Salam Khub hasti density $\bf f$ agr bashe en ro dorost kard force density $\bf t$ at both points} \label{fig:m}

\end{figure}

Best Answer

I suggest you load the subcaption package, which provides an environment called subfigure. I further suggest you load the cleveref package to help streamline making cross-references to items such as subfigures.

enter image description here

\documentclass{article}
\usepackage{subcaption} % provides 'subfigure' environment
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\usepackage[capitalize]{cleveref} % for "clever" cross-referencing
\begin{document}

\begin{figure}

\begin{subfigure}{0.475\textwidth}
  \includegraphics[width=\linewidth]{fig1}
  \caption{First subfigure} \label{fig:1a}
\end{subfigure}\hfill% leave no blank line between subfigures
\begin{subfigure}{0.475\textwidth}
  \includegraphics[width=\linewidth]{fig2}
  \caption{Second subfigure} \label{fig:1b}
\end{subfigure}

\caption{A figure with two subfigures} \label{fig:1}

\end{figure}

\noindent
A cross-reference to \cref{fig:1b}.
\end{document}

Addendum: If you don't need to cross-reference the subfigures individually, and if you're fine with providing a long caption that describes the contents of the two image files, there's certainly no need to load the subcaption package or to place the image files in minipage environments.

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx} % omit 'demo' option in real document
\usepackage[capitalize]{cleveref} % for "clever" cross-referencing
\begin{document}

\begin{figure}

\includegraphics[width=0.475\textwidth]{fig1}
\hfill
\includegraphics[width=0.475\textwidth]{fig2}

\caption{Left-hand panel: taghyer jabejaei, $R$ is the reference configuration and $D$ is the deformed configuration. Right-hand panel: Salam Khub hasti density $\mathbf{f}$ agr bashe en ro dorost kard force density $\mathbf{t}$ at both points} \label{fig:m}
\end{figure}

\noindent
A cross-reference to \cref{fig:m}.
\end{document}
Related Question