# Subfigure problems [duplicate]

This is my first time using Latex. I would like to get help with sub-figure issue that I am facing.

The paper is IEEE format. I used the following code:

\begin{figure*}[!htbp]
\centering
\begin{subfigure}
\includegraphics[width=\textwidth]{Fig2a.jpg}
\caption{LV}
\label{fig:2a}
\end{subfigure}

\begin{subfigure}
\includegraphics[width=\textwidth]{Fig2b.jpg}
\caption{MV}
\label{fig:2b}
\end{subfigure}
\caption{Location of DVR}
\end{figure*}


This gave me the following output:

As you can see, the sub-captions are not proper. It takes each sub-captions as a new figure. Also, it throws an error saying '\begin{figure*} on input line 338 ended by \end{subfigure}.

I searched in internet and added the package \usepackage{subfigure} and the output becomes:

so I added \usepackage{subcaption} and the output is weird with 229 errors:

I am not sure what am I doing wrong. I tried adding the \linewidth cmd to the code but nothing seems to solve the issue.

• Please prepare a complete small example code that allows others to reporduce the output you get. Apr 18 '20 at 13:22
• subfigure is deprecated and should not be used any more. If you add subcaption package to your preamble, the individual subfigure environments need a width as in \begin{subfigure}{\linewidth}. Apr 18 '20 at 13:24
• Please clarify which documentclass you use. If you use IEEEtran, you might want to use the subfig package, since the class documentation recommends using subfig over subcaption. Apr 18 '20 at 13:26
• @leandriis I am using 'conference_10179.tex' to write the paper. As I am totally new, I am not sure if this is the answer to your question. I found that subcaption package doesn't work with \begin{subfigure}{\textwidth}, when I changed it to \begin{subfigure}{\linewidth}, it worked. Thank you. Apr 18 '20 at 15:07

I suspect that you use obsolete package subfigure Instead it try to use subcaption:

\documentclass[12pt]{ieeetran}
\usepackage{subcaption}
\usepackage{graphicx}

\begin{document}
\begin{figure*}
\centering
\begin{subfigure}{0.8\linewidth}
\includegraphics[width=\linewidth]{example-image}
\caption{LV}
\label{fig:2a}
\end{subfigure}

\begin{subfigure}{0.8\linewidth}
\includegraphics[width=\linewidth]{example-image}
\caption{MV}
\label{fig:2b}
\end{subfigure}
\caption{Location of DVR}
\end{figure*}
\end{document}


which gives:

Edit: A stated @leandriis in his coment below, IEEEtran documentation sugest to use subfig package, which define \subfloat environment:

\documentclass[12pt]{ieeetran}
\usepackage{subfig}
\usepackage{graphicx}

\begin{document}
\begin{figure*}
\centering
\subfloat[LW \label{fig:2a}]{\includegraphics[width=0.8\linewidth]{example-image-duck}}

\subfloat[LW \label{fig:2b}]{\includegraphics[width=0.8\linewidth]{example-image-duck}}
\caption{Location of DVR}
\end{figure*}
\end{document}


Result is slightly nicer as before:

• The documentation of ieeetran suggests using subfiginstead of subcaption. Apr 18 '20 at 13:37
• @zarko Thank you for the answer. I tried \usepackage{subcaption} earlier and it was giving me error. Now looking in to your code, I changed the 'textwidth' in my code to 'linewidth' and it is working perfectly. Thank you so much. I am not sure how it is linked but it works. Apr 18 '20 at 15:03