0

What number am I missing the moment I want a subcaption for my subfigure it tells me I'm missing a number for some reason. The error also disappears if I remove the roman counter option.

\documentclass[a4paper,UKenglish]{article}
\usepackage{graphicx}
\usepackage{caption}
 \usepackage{subcaption}
 \renewcommand{\thesubfigure}{\roman{counter}} 
\begin{document}
asdfasdf 

\begin{figure}
    \centering
   \begin{subfigure}[b]{0.45\textwidth}
    \includegraphics[scale=0.5]{example-grid-100x100pt}
    \caption{asdfsfad}
   \end{subfigure} 
   \begin{subfigure}[b]{0.45\textwidth}
      \includegraphics[scale=0.5]{example-grid-100x100pt}
   \end{subfigure}
    \caption{Caption}
   
\end{figure}


\end{document}

\end{document}
13
  • 1
    are you using both packages subfigure and subcaption -- have a look here -- tex.stackexchange.com/questions/19946/…
    – js bibra
    Dec 13, 2020 at 6:05
  • @jsbibra I didn't load the subfigure package though is there a way to stop it from loading?
    – Hao S
    Dec 13, 2020 at 6:07
  • Does your code example actually lead to the error message? Dec 13, 2020 at 6:11
  • @Dr.ManuelKuehner sorry I accidentally deleted a line \usepackage{graphicx} fixed now
    – Hao S
    Dec 13, 2020 at 6:19
  • Please make the code compilable without pic1.png etc, see tex.stackexchange.com/questions/231738. Do you know that you can format the code in your question (in the editor)? Dec 13, 2020 at 6:20

1 Answer 1

4

You use wrong name for subfigure caption's number. Instead of counter it must be subfigure (see @Dr. Manuel Kuehner answer).I guess that you like to obtain the following result:

enter image description here

Complete MWE is:

\documentclass[a4paper,UKenglish]{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\renewcommand\thesubfigure{\roman{subfigure}}
 
\usepackage{lipsum} % added for generation of dummy text

\begin{document}
\lipsum[11]

\begin{figure}[ht]
    \centering
    \begin{subfigure}[b]{0.45\textwidth}
    \centering
\includegraphics[scale=0.5]{example-grid-100x100pt}
\caption{first subfigure}
   \end{subfigure}
\hfil
   \begin{subfigure}[b]{0.45\textwidth}
    \centering
\includegraphics[scale=0.5]{example-grid-100x100pt}
\caption{second subfigure}
   \end{subfigure}
\caption{Caption}
\end{figure}

\end{document}
1
  • +1: Very good! @HaoS Please accept this answer. Dec 13, 2020 at 8:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .