I tried to use the tipps in this post cleveref and algorithm2e. But it does not lead to the correct referencing, what is done wrong here and how to i get cref running with algorithm?
\documentclass[]{article}
\usepackage{subcaption}
\usepackage{algorithm}
\usepackage{algpseudocode}
%\input{Packages}
\usepackage{cleveref}
\crefname{algocf}{alg.}{algs.}
\Crefname{algocf}{Algorithm}{Algorithms}
\begin{document}
\section{asdja}
\cref{alg:a} is a algorithm.
\ref{alg:a} is a glrotihm
\begin{algorithm}
\label{alg:a}
\begin{algorithmic}[1]
\State x
\end{algorithmic}
\caption{This is an algorithm}
\end{algorithm}
\end{document}
\labelafter the\captioncommand. If you use\caption{This is an algorithm}\label{alg:a}, if works fine. See Why does an environment's label have to appear after the caption? – frougon Apr 15 '20 at 17:15algorithminstead ofalgocfin the\crefnameand\Crefnamecalls if you want them to be effective. Thealgocfcounter is used by thealgorithm2epackage, which your sample code doesn't use. So, this was not completely a duplicate: half of the problem is the duplicate, the other half is what I said in this comment. – frougon Apr 15 '20 at 21:44`\usepackage[ruled,vlined,portuguese]{algorithm2e} % ... \usepackage{cleveref} % ... %\Crefname{algocf}{Algoritmo}{Algoritmos} % <----- DOESN'T WORK! \Crefname{algorithm}{Algoritmo}{Algoritmos} % <----- This works! % ... \begin{algorithm}[H] % ... \caption{How to write algorithms\label{algo:xxx}} \end{algorithm}
Teste \Cref{algo:xxx}.`
– igormcoelho Aug 02 '21 at 19:06\label{algo:xxx}after the\caption{...}, not inside its argument. ;) – frougon Aug 02 '21 at 22:08\labelis something legal in the mandatory arg of\part,\chapter,\section, etc. and, after a quick look at the code for\captionin the LaTeX kernel, it seems to me that it can work there too (a quick test agrees). One learns every day. Good night! – frougon Aug 03 '21 at 20:51