0

I am including a series of figures in minipages (using \captionof for captions) but unfortunately the captions are not showing the figure numbers at all. Can someone help me here please? Code and image below. Thank you

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{titlepic}
\usepackage{amsmath}
\usepackage{enumitem}% http://ctan.org/pkg/enumerate
\usepackage{rotating} 
\usepackage{float}
\usepackage{multirow}
\usepackage[margin=0.5in]{geometry}
\usepackage{titling}


\begin{document}
\SweaveOpts{concordance=TRUE}

\section{Disability}\label{sect:Disability}

\begin{minipage}{.5\linewidth}
    \centering
  \includegraphics[width=1\textwidth]{../figures/DisED.pdf}
  \captionof{}{Percentage of Population with a Disability (Both Sexes)}
  \label{fig:test1}
\end{minipage}%
\begin{minipage}{.5\linewidth}
  \centering
  \includegraphics[width=1\textwidth]{../figures/DisEDFemale.pdf}
  \captionof{}{Percentage of Population with a Disability (Female)}
  \label{fig:test2}
\end{minipage}

\begin{minipage}{.5\linewidth}
  \centering
  \includegraphics[width=1\textwidth]{../figures/DisEDMale.pdf}
  \captionof{}{Percentage of Population with a Disability (Male)}
  \label{fig:test2}
\end{minipage}
\pagebreak

\end{document}

enter image description here

3
  • 2
    You need to give the counter-type in the first argument of \captionof. Instead of \captionof{}{<stuff>} use \captionof{figure}{<stuff>}.
    – Skillmon
    Oct 12, 2023 at 10:13
  • your example gives ! Undefined control sequence. l.14 \SweaveOpts and ! Undefined control sequence. l.21 \captionof Please make sure any example you post is an example of the problem you are asking about Oct 12, 2023 at 10:39
  • Thanks Skillmon. Your solution just put "figure" in the caption but no number. I then put \use-package{capt-of} and it fixed the numbering. Apols David, I was using sweave in R and forgot to remove some code
    – osckt
    Oct 12, 2023 at 11:01

3 Answers 3

3

Your example does not define \captionof at all but if the example is fixed to be

\documentclass{article}

\usepackage{capt-of}

\begin{document}


\section{Disability}\label{sect:Disability}

\begin{minipage}{.5\linewidth}
    \centering
%  \includegraphics[width=1\textwidth]{../figures/DisED.pdf}
  \captionof{}{Percentage of Population with a Disability (Both Sexes)}
  \label{fig:test1}
\end{minipage}%


\end{document}

Then it generates the error

! LaTeX Error: No counter '' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.13   \captionof{}
                   {Percentage of Population with a Disability (Both Sexes)}
? 

After any error the pdf is just a debugging aid and not intended to be usable.

The error message highlights the empty argument, which should be figure.

\documentclass{article}

\usepackage{capt-of}

\begin{document}


\section{Disability}\label{sect:Disability}

\begin{minipage}{.5\linewidth}
    \centering
%  \includegraphics[width=1\textwidth]{../figures/DisED.pdf}
  \captionof{figure}{Percentage of Population with a Disability (Both Sexes)}
  \label{fig:test1}
\end{minipage}%


\end{document}

enter image description here

2
  • Thanks David. I'm using sweave within r to create the files so debugging isn't as easy. I didnt get that error at all within R. your answer works perfectly!
    – osckt
    Oct 12, 2023 at 11:00
  • 1
    tex would have generated the error: it must be in the generated log file if nowhere else. R may hide the terminal output (which is unfortunate but not uncommon for systems using tex in the background) @osckt Oct 12, 2023 at 11:01
1

put all in a figure environment:

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{titlepic}
\usepackage{amsmath}
\usepackage{enumitem}% http://ctan.org/pkg/enumerate
\usepackage{rotating} 
\usepackage{float}
\usepackage{multirow}
\usepackage[margin=0.5in]{geometry}
\usepackage{titling}


\begin{document}
    
\section{Disability}\label{sect:Disability}

\begin{figure}[!htb]
    \begin{minipage}[b]{.49\linewidth}
    \includegraphics[width=\textwidth]{../figures/DisED.pdf}%
    \end{minipage}\hfill
    \begin{minipage}[b]{.49\linewidth}
    \includegraphics[width=\textwidth]{../figures/DisEDFemale.pdf}
    \end{minipage}
    
    \vspace{-\medskipamount}
    \begin{minipage}[t]{.49\linewidth}
       \caption{Percentage of Population with a Disability (Both Sexes)}\label{fig:test1}
    \end{minipage}\hfill
    \begin{minipage}[t]{.49\linewidth}
        \caption{Percentage of Population with a Disability (Female)}\label{fig:test2}
    \end{minipage}
    
    \begin{minipage}{.5\linewidth}
    \includegraphics[width=\textwidth]{../figures/DisEDMale.pdf}
    \caption{Percentage of Population with a Disability (Male)}\label{fig:test3}
    \end{minipage}
\end{figure}
    
\end{document}

enter image description here

1

Insert your mini pages with figures in the figure environment document and use standard \caption commands:

\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[demo]{graphicx}  % in real document remove option "demo"
\usepackage{caption}

\begin{document}

\section{Disability}
\label{sect:Disability}

\begin{figure}[htb]
\captionsetup{skip=1ex, belowskip=2ex}
\setkeys{Gin}{width=\linewidth}
    \begin{minipage}[b]{.48\linewidth}
\includegraphics{../figures/DisED.pdf}%
\caption{Percentage of Population with a Disability (Both Sexes)}\label{fig:test1}
    \end{minipage}\hfill
    \begin{minipage}[b]{.48\linewidth}
\includegraphics{../figures/DisEDFemale.pdf}
\caption{Percentage of Population with a Disability (Female)}\label{fig:test2}
    \end{minipage}

    \begin{minipage}{.48\linewidth}
\includegraphics{../figures/DisEDMale.pdf}
\caption{Percentage of Population with a Disability (Male)}\label{fig:test3}
    \end{minipage}
\end{figure}

\end{document}

enter image description here

You must log in to answer this question.

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