[Tex/LaTex] Error in figure with subfigures in beamer missing value, treated as zero

beamerfloats

I'm trying to put into a beamer presentation on overleaf a graph that I already have in a document of class article.
However, it's not working. It says missing value, treated as 0 of line \end{frame}. Might be a package missing, but which one? Thanks!

\documentclass{beamer}
\usetheme{Madrid} % new 
\usepackage{hyperref}
\setbeamercovered{transparent}
\usepackage{subfigure}
\usepackage{graphicx}
\usepackage{amsmath}

\begin{document}

\begin{frame}
\frametitle{Distribution of $W$}

\begin{figure}
\caption{Distribution of the $W$ statistic} \label{w_c}
  \begin{subfigure}{\textwidth}
  \caption{Singh-Madalla with $c=1.7$} \label{w_c_1.7}
  \includegraphics[width=0.23\textwidth]{gini_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge_0_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge_1_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge_2_fim2.pdf}
  \end{subfigure}
  \bigskip
  \begin{subfigure}{\textwidth}
  \caption{Singh-Madalla with $c=1.2$} \label{w_c_1.2}
  \includegraphics[width=0.23\textwidth]{gini_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge0_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge1_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth]{ge2_fim_12.pdf}
  \end{subfigure} 
\end{figure}
\end{frame}
\end{document}

Best Answer

  • don't use subfigure, it is obsolete package. instead it rather use subcaption package
  • package hypperref had to be loaded last in preamble, however, it is already loaded by beamer document class (see samcarter comment below), so it is better to delete it
  • graphicx is loaded by beamer document class.

enter image description here

\documentclass[demo]{beamer}
\usetheme{Madrid} % new
\setbeamercovered{transparent}
\usepackage{subcaption}

\begin{document}

\begin{frame}
\frametitle{Distribution of $W$}

\begin{figure}
\caption{Distribution of the $W$ statistic} \label{w_c}
  \begin{subfigure}{\textwidth}
  \caption{Singh-Madalla with $c=1.7$} \label{w_c_1.7}
  \includegraphics[width=0.23\textwidth,height=22mm]{gini_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge_0_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge_1_fim2.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge_2_fim2.pdf}
  \end{subfigure}
  \bigskip
  \begin{subfigure}{\textwidth}
  \caption{Singh-Madalla with $c=1.2$} \label{w_c_1.2}
  \includegraphics[width=0.23\textwidth,height=22mm]{gini_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge0_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge1_fim12.pdf}\hfill
  \includegraphics[width=0.23\textwidth,height=22mm]{ge2_fim_12.pdf}
  \end{subfigure}
\end{figure}
\end{frame}
\end{document}

Option demo at \documentclass[demo]graphicx is passed to graphics package and in real use had to be removed. It is used here used because we haven't your actual images (it generate black squares instead them).