Math & Science\caption outside float in algorithm package

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
vivek9837
Posts: 1
Joined: Mon Apr 04, 2016 12:55 pm

\caption outside float in algorithm package

Post by vivek9837 »

I am trying to write the following algorithm using latex

Code: Select all

\documentclass{article}
\usepackage{algorithm,algpseudocode}

\begin{document}
\begin{algorithm}
  \caption{Euclid's algorithm}\label{euclid}
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The gcd of $a$ and $b$}
      \State $r \gets a \bmod b$
      \While{$r \neq 0$}\Comment{We have the answer if $r$ is $0$}
        \State $a \gets b$
        \State $b \gets r$
        \State $r \gets a \bmod b$
      \EndWhile\label{euclidendwhile}
      \State \textbf{return} $b$\Comment{The gcd is $b$}
    \EndProcedure
  \end{algorithmic}
\end{algorithm}

\end{document}
but i am getting the following error

Code: Select all

./test2.tex:6:\caption outside float. \caption
Kindly help

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

\caption outside float in algorithm package

Post by Johannes_B »

Welcome, the code you posted works fine. Maybe you forgot an algorithm environment in your real document.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply