Right now I have an algorithm and I wish to reference it throughout a body of text.
However, the way that the algorithm is being reference is awkward. See top figure. Using \autoref
, the algorithm is reference simply as "algorithm 1". I wish instead to reference a table that contain algorithm 1, and refer to readers to look at the table instead.
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{thmtools}
\setlength\parindent{0pt}
\usepackage[linesnumbered,ruled]{algorithm2e}
\usepackage{hyperref}
\begin{document}
\section{Introduction}
{\LinesNumberedHidden
\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\SetAlgorithmName{Algorithm}{}
Initialize: $x^0$ = 0;
\begin{enumerate}
\item Pour hot coal on $f(x)$
\item Freeze coal until $\|f(x)\|_\infty < \epsilon$
\end{enumerate}
\caption{Meta-Coal Algorithm}
\label{algo:Coal Meta-Heuristic}
\end{algorithm}}
Look at my beautiful algorithm in \autoref{algo:Coal Meta-Heuristic}
\end{document}
Instead, I want something like this:
Now I am referring the algorithm that is CONTAINED in a table, I feel referencing this table more natural this way. The table's name could go on top of the algorithm or at the bottom (as currently shown). The caption for that table could be called something like "Description of Meta Coal algorithm" or just "Meta Coal algorithm" (as currently shown).
However, if I try to place the algorithm block inside of a \begin{table}
the entire thing fails to compile!
\begin{table}
{\LinesNumberedHidden
\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\SetAlgorithmName{Algorithm}{}
Initialize: $x^0$ = 0;
\begin{enumerate}
\item Pour hot coal on $f(x)$
\item Freeze coal until $\|f(x)\|_\infty < \epsilon$
\end{enumerate}
\caption{Meta-Coal Algorithm}
\label{algo:Coal Meta-Heuristic}
\end{algorithm}}
\end{table}
Does anyone know if there is a way to accomplish what I want with minimal effort?
Best Answer
Use the
H
specifier so the algorithm is not more a floating object and can be put inside a table.