1

I am preparing a manuscript to be submitted to a IUCr journal. By using the provided template (http://journals.iucr.org/s/services/latexstyle.html) where the documentclass is set to iucr, I found my algorithm boxes created using algorithm2e were not showing captions. The captions of figures were displayed normally. After switching to \documentclass{article}, the algorithm box captions came back to normal.

An MWE is listed below:

\documentclass[preprint]{iucr} 
\usepackage{algorithm2e}
\usepackage{amsmath}
\RestyleAlgo{boxruled}

\begin{document} 
\begin{algorithm}[H]
\SetAlgoLined
\KwIn{$g$: the scan grid configuration}
\KwIn{$\Theta$: the list of projection angles}
\For{$z$ in $g_z$}{
  \For{$y$ in $g_y$}{
    \For{$x$ in $g_x$}{
      \For{$\theta$ in $\Theta$}{
          Acquire projection image
      }
    }
  }
}
End Acquisition
\label{box:acq_local}
\caption{Algorithm for image acquisition used for local tomogram stitching.}
\end{algorithm}
\end{document}

The printed algorithm box looks like this - although \caption is provided, its missing in the pdf. enter image description here

The cls file of the IUCr template can be found via the link above.

Any thoughts are appreciated.

7
  • Please post the class file here as well, I don't want to follow external links in order to pursue this issue
    – user31729
    Mar 3, 2018 at 18:03
  • The codes are too long to be placed in the post, is there another way to present it with the issue? Mar 3, 2018 at 18:10
  • 1
    Label have to placed after caption.
    – koleygr
    Mar 3, 2018 at 18:51
  • 1
    @koleygr: Yes, but that's unrelated to the main issue here.
    – user31729
    Mar 3, 2018 at 22:03
  • 1
    @ChristianHupfer I thought to write "off-topic" in the message for this reason... but didn't "herd" correct to me... (Now that I thought it, in such cases I will write "Not the main issue"...)
    – koleygr
    Mar 3, 2018 at 22:09

1 Answer 1

1

The iucr class redefines \caption based on whether the float is a figure or a table (or a class-specific example environment). Unfortunately there is no default case for other types of float, such as algorithms, which means that for these floats the definition of \caption is blank.

You can provide a custom command for the caption (borrowed from article) and use that for all floats other than figures and tables. It appears that this solution preserves numbering and correct references (see example below).

Note that the journal may have additional requirements on the placement, font style, abbreviation etc. of custom captions. Also: it may be a good idea to mention to the journal editor that this issue should be addressed in their document class.

MWE:

\documentclass[preprint]{iucr} 
\usepackage{algorithm2e}
\usepackage{amsmath}
\RestyleAlgo{boxruled}

\makeatletter
\newcommand{\mycaption}{%
\ifx \@captype \@undefined \@latex@error {\noexpand \caption outside float}\@ehd \expandafter \@gobble \else \refstepcounter \@captype \expandafter \@firstofone \fi {\@dblarg {\@caption \@captype }}%
}%
\makeatother

\begin{document}
Consider Figures \ref{fig:first} and \ref{fig:second} and Algorithms \ref{box:acq_local} and \ref{box:acq_short}.

\begin{figure}
\fbox{A figure}
\caption{Figure caption}
\label{fig:first}
\end{figure}

\begin{algorithm}
\SetAlgoLined
\KwIn{$g$: the scan grid configuration}
\KwIn{$\Theta$: the list of projection angles}
\For{$z$ in $g_z$}{
  \For{$y$ in $g_y$}{
    \For{$x$ in $g_x$}{
      \For{$\theta$ in $\Theta$}{
          Acquire projection image
      }
    }
  }
}
End Acquisition
\mycaption{Algorithm for image acquisition used for local tomogram stitching.}
\label{box:acq_local}
\end{algorithm}

\begin{figure}
\fbox{Another figure}
\caption{Other figure caption}
\label{fig:second}
\end{figure}

\begin{algorithm}
\SetAlgoLined
\KwIn{$g$: the scan grid configuration}
\KwIn{$\Theta$: the list of projection angles}
Do Magic\;
End Acquisition
\mycaption{Short algorithm for image acquisition.}
\label{box:acq_short}
\end{algorithm}

\end{document}

Result:

enter image description here

1
  • It worked out smoothly, thank you so much! I will definitely mention the issue to the editors. Mar 5, 2018 at 16:19

You must log in to answer this question.

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