# algorithmic: Reduce space between floatname and caption when unnumbered

I want to use the algorithmic package unnumbered.

I tried to do this with \renewcommand{\thealgorithm}{}, but it seems that the space between the floatname Algorithm and the caption great is to big.

Here my MWE:

\documentclass{article}
\usepackage{algorithmic}
\usepackage{algorithm}

\begin{document}

\begin{algorithm}[H]
\caption{great}
\begin{algorithmic}
\STATE dummy
\end{algorithmic}
\end{algorithm}

\renewcommand{\thealgorithm}{}

\begin{algorithm}[H]
\caption{great}
\begin{algorithmic}
\STATE dummy
\end{algorithmic}
\end{algorithm}

\end{document}


Output:

Using unnumbered algorithms requires you to remove the numbering in two locations. The first is in the algorithms' \caption, while the second is in the ToC. The patch below removes exactly that:

\usepackage{etoolbox}
\makeatletter
% Remove \thealgorithm from ToC
\patchcmd{\@float@c@algorithm}% <cmd>
{\@nameuse{the#1}}% <search>
{}% <replace>
{}{}% <succes><failure>
% Remove \thealgorithm from \caption
\renewcommand{\fnum@algorithm}{\fname@algorithm}
\makeatother


The following example shows the difference:

\documentclass{article}

\usepackage{algorithm}

\usepackage{etoolbox}

\begin{document}

\listofalgorithms

\begin{algorithm}[H]
\caption{great}
\end{algorithm}

\makeatletter
% Remove \thealgorithm from ToC
\patchcmd{\@float@c@algorithm}% <cmd>
{\@nameuse{the#1}}% <search>
{}% <replace>
{}{}% <succes><failure>
% Remove \thealgorithm from \caption
\renewcommand{\fnum@algorithm}{\fname@algorithm}
\makeatother

\begin{algorithm}[H]
\caption{great}
\end{algorithm}

\end{document}


Note that the algorithm counter is still stepped, but that might not be a problem if all your algorithms should be unnumbered. If you want only some to be unnumbered, it would be best to create a separate environment to differentiate between the types.

If you want the spacing in the ToC to also be adjusted so you don't have a big gap between the margin and the algorithm caption, then you can remove the entire \numberline insertion into the .loa using this patch instead:

\makeatletter
% Remove \thealgorithm from ToC
\patchcmd{\@float@c@algorithm}% <cmd>
{\protect\numberline{\@nameuse{the#1}}}% <search>
{}% <replace>
{}{}% <succes><failure>
% Remove \thealgorithm from \caption
\renewcommand{\fnum@algorithm}{\fname@algorithm}
\makeatother


Loading subcaption interferes with the above update. Specifically, the \caption isn't set in the usual way. So, we can capture the usual algorithm's \caption before loading subcaption and replace it back with the first call to \begin{algorithm}:

\usepackage{algorithm}
\makeatletter
\let\alg@caption\caption% Store \caption in \alg@caption
\makeatother
\usepackage{subcaption}
\usepackage{etoolbox}

\makeatletter
% Remove \thealgorithm from ToC
\patchcmd{\@float@c@algorithm}% <cmd>
{\@nameuse{the#1}}% <search>
{}% <replace>
{}{}% <succes><failure>
% Remove \thealgorithm from \caption
\renewcommand{\fnum@algorithm}{\fname@algorithm}
% Redeploy \caption at \begin{algorithm}
\makeatother

• I use the subcaption package, which causes a bug...
– Ben
Aug 30 '16 at 20:10
• @Ben: I'll work on an update later...
– Werner
Aug 30 '16 at 20:33
• Do you have a solution? just don't want to be forgotten
– Ben
Aug 31 '16 at 1:31
• @Ben: See then post-ending update.
– Werner
Aug 31 '16 at 3:59

If the subcaption (or caption) package is used anyway the caption package option labelformat=unnumbered could be used:

\documentclass{article}
\usepackage{algorithmic}
\usepackage{algorithm}
\usepackage{subcaption}

\captionsetup[algorithm]{labelformat=unnumbered}

\begin{document}

\begin{algorithm}[H]
\caption{great}
\begin{algorithmic}
\STATE dummy
\end{algorithmic}
\end{algorithm}

\end{document}