TransWikia.com

Missing number treated as zero in subfigure caption

TeX - LaTeX Asked on December 25, 2020

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.45textwidth}
    includegraphics[scale=0.5]{example-grid-100x100pt}
    caption{asdfsfad}
   end{subfigure} 
   begin{subfigure}[b]{0.45textwidth}
      includegraphics[scale=0.5]{example-grid-100x100pt}
   end{subfigure}
    caption{Caption}
   
end{figure}


end{document}

end{document}

One Answer

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}
renewcommandthesubfigure{roman{subfigure}}
 
usepackage{lipsum} % added for generation of dummy text

begin{document}
lipsum[11]

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

end{document}

Correct answer by Zarko on December 25, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP