4

I'm am using the IEEE Access Latex template and I'm getting errors when using the caption command in a listing environment. This does not happen with the IEEEtran template.

For example, this code works:

\documentclass{ieeeaccess}
\usepackage{graphicx} 
\usepackage{listings}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{lstlisting}[label=listing1, language=C]
int main(void)
{
        printf("Hello world\n");
}
\end{lstlisting}
\end{document}

But the following does not, and the only difference is the caption command:

\documentclass{ieeeaccess}
\usepackage{graphicx} 
\usepackage{listings}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
\begin{lstlisting}[label=listing1, language=C, caption=Listing 1]
int main(void)
{
        printf("Hello world\n");
}
\end{lstlisting}
\end{document}

In fact, the result is a series of errors like this:

! Undefined control sequence. \@makecaption ...capfont #2\strut }\ifdim \xfigwd \columnwidth \setbox \@te... l.12 ...el=listing1, language=C, caption=Listing1]

! Missing number, treated as zero.

l.12 ...el=listing1, language=C, caption=Listing1]

! Illegal unit of measure (pt inserted).

l.12 ...el=listing1, language=C, caption=Listing1]

! Infinite glue shrinkage found on current page. \@makecaption ...\ }}{\vss \raggedright \noindent \unhbox \@tempboxa \figcap... l.12 ...el=listing1, language=C, caption=Listing1]

Carlos
  • 143

2 Answers2

3

ieeeaccess redefines the caption command and uses a length called \xfigwd which is normally set from a figure or table environment. As you listing uses neither of these environments, you'll have to manually do it:

\documentclass{ieeeaccess}
\usepackage{graphicx} 
\usepackage{listings}
\usepackage{lipsum}

\begin{document}
\lipsum[1]

\begingroup
\newlength{\xfigwd}
\setlength{\xfigwd}{\textwidth}
\begin{lstlisting}[label=listing1, language=C, caption={hgd}]
int main(void)
{
        printf("Hello world\n");
}
\end{lstlisting}
\endgroup
\EOD

\end{document}

enter image description here

0

If someone is still struggling with this problem here is my solution:

Put your listing in minipage and remove the indent for new paragraph with \hspace*{-\parindent}% (it's a hint from Why is the minipage indented on the left?

\hspace*{-\parindent}%
\begin{minipage}[c]{\linewidth}
\begin{lstlisting}[label=listing1, language=C, caption={hgd}]
int main(void)
{
        printf("Hello world\n");
}
\end{lstlisting}
\end{minipage}

and add this \makeatletter snippet after including listings package and before \begin{document}:

\documentclass{ieeeaccess}
\usepackage{graphicx} 
\usepackage{listings}
\usepackage{lipsum}

\makeatletter
\def\lst@makecaption{%
  \def\@captype{table}%
  \@makecaption
}
\makeatother

\begin{document}

it makes ieeeaccess treats listing's caption like a table's caption and adds extra vertical space between caption and listing. This snippet is taken from: IEEE Latex Listing

levy
  • 1
  • 1