You could use the line numbers to act as your labels, and reference them in a "go to" command.

In the following minimal example, I've defined a "go to" command using the following (I'm using `algorithmicx`

):

```
\algnewcommand{\algorithmicgoto}{\textbf{go to}}%
\algnewcommand{\Goto}[1]{\algorithmicgoto~\ref{#1}}%
```

`\algorithmicgoto`

provides the style, while `\Goto{<label>}`

is the actual command to be used inside the `algorithmic`

environment. Here `<label>`

is a label defined on any line using `\label{<label>}`

:

```
\documentclass{article}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\begin{document}
\algnewcommand{\algorithmicgoto}{\textbf{go to}}%
\algnewcommand{\Goto}[1]{\algorithmicgoto~\ref{#1}}%
\begin{algorithm}
\caption{Euclid’s algorithm}\label{euclid}
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0} \label{marker}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile
\State \textbf{return} $b$\Comment{The gcd is b}
\State \Goto{marker}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
```

It is also possible combine the `\State`

command in `\Goto`

using:

```
\algnewcommand{\Goto}[1]{\State \algorithmicgoto~\ref{#1}}
```

However, this would make it impossible to use `\Goto`

with anything else on a line, since it issues a `\State`

, which starts a new line in the algorithm.

Here is another approach, still using `algorithmicx`

. This time I've used a slightly different version of `\Goto`

(using `xspace`

). Additionally there's a `\Label`

command defined. This issues a `\State`

command, followed by `\unskip`

which removed any horizontal skip issued internally by `algorithmicx`

to indent the block by the appropriate amount. This allows you to typeset "labels" flush to the left margin in your own style:

```
\documentclass{article}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{xspace}% http://ctan.org/pkg/xspace
\begin{document}
\algnewcommand{\algorithmicgoto}{\textbf{go to}}%
\algnewcommand{\Goto}{\algorithmicgoto\xspace}%
\algnewcommand{\Label}{\State\unskip}
\begin{algorithm}
\caption{Euclid’s algorithm}\label{euclid}
\begin{algorithmic}
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\Label \texttt{marker:}
\While{$r\not=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
\State \textbf{return} $b$\Comment{The gcd is b}
\State \Goto \texttt{marker}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\end{document}
```

## Some not-so-optimal approaches

One attempt at keeping algorithms together would be to use the same float specifier for both floats:

```
%...
\begin{algorithm}[t]% First algorithm
%...
\end{algorithm}
\begin{algorithm}[t]% Second algorithm
%...
\end{algorithm}
%...
```

LaTeX will ensure that they follow in sequence since the floats are managed by a list that is flushed in a FIFO (first-in-first-out) manner. However, this is very unreliable since float placement is dependent on the number of floats already on the page, as well as the remaining space on a page. So, algorithms could be broken fairly easily in this way.

Another attempt would be to use the `H`

float specifier supplied by the `float`

package. This float specifier virtually removed the float-ness of a float and places it in the text where the environment is called:

```
%...
\begin{algorithm}[H]% First algorithm
%...
\end{algorithm}
\begin{algorithm}[H]% Second algorithm
%...
\end{algorithm}
%...
```

Although this works pretty well, you lose the mobility offered by a float, so algorithms will appear where you put them. Moreover, this approach is not perfect around page boundaries, where the two algorithms could be separated. Moreover, the effects could be worse if using the `H`

float specifier for some algorithms and other (regular) float specifiers for other non-stick-together algorithms. Here is a small example that illustrates this problematic instance:

```
\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{float}% http://ctan.org/pkg/float
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\listofalgorithms
\section{First section}
\lipsum[1-2]
\begin{algorithm}[H]
\caption{First algorithm}\label{first-alg}%
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\algstore{euclidA}
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[H]
\caption{Second algorithm}\label{second-alg}
\begin{algorithmic}[1]
\algrestore{euclidA}
\State $a\gets b$
\State $b\gets r$
\algstore{euclidB}
\end{algorithmic}
\end{algorithm}
\lipsum[2]
\section{Second section}
\lipsum[3]
\begin{algorithm}[t]
\caption{Third algorithm}\label{third-alg}
\begin{algorithmic}[1]
\algrestore{euclidB}
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\lipsum[4]
\end{document}
```

The example has been chosen specifically to break the two algorithms that are supposed to stick together across the first page boundary, while the third algorithm is left to float. As such, the sequence of algorithms displayed in the output is jumbled: Algorithm 1 is followed by Algorithm 3, which is followed by Algorithm 2:

Not only that, as can be seen from the output (click to enlarge), the order in the "List of Algorithms" is also incorrect.

## A slightly manual (but functional) approach

The idea is to use an existing float (like `figure`

) as a float wrapper and define some commands that mimic the captioning and typesetting behaviour of the `algorithm`

package. It is perfectly fine to use a `figure`

as a float wrapper, just as long as there is no "offical `\caption`

" used inside (which will typeset a *figure* caption, and would eventually make its way into the LoF).

I've decided to use the `ruled`

float style of `algorithm`

. Additionally, I've chosen `algpseudocode`

(from the `algorithmicx`

bundle) for typesetting the algorithm within an `algorithmic`

environment. Similar functionality is provided by the `algorithmic`

package (also from the `algorithms`

bundle), so the example is transferable^{*}.

In order to mimic the captioning style of `ruled`

, a new macro `\algcaption[<LoA>]{<caption>}`

should be used. This typesets a thick `0.8pt`

rule (`\toprule`

), followed by the caption (flush left), followed by another rule (`\midrule`

), taken directly from the `float`

package. The `algorithmic`

environment should be finished off with a `\bottomrule`

, making the approach very much `tabular`

-like.

```
\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{ifmtarg}% http://ctan.org/pkg/ifmtarg
\makeatletter
\newcommand{\listofalgorithms}{\listof{algorithm}{List of Algorithms}}%
\newcommand{\toprule}{\hrule height.8pt depth0pt \kern2pt} % Caption top horizontal rule+skip
\newcommand{\midrule}{\kern2pt\hrule\kern2pt} % Caption bottom (or mid) horizontal rule+skip
\newcommand{\bottomrule}{\kern2pt\hrule\relax}% Algorithm bottom rule
\newcommand{\algcaption}[2][]{%
\refstepcounter{algorithm}%
\@ifmtarg{#1}
{\addcontentsline{loa}{figure}{\protect\numberline{\thealgorithm}{\ignorespaces #2}}}
{\addcontentsline{loa}{figure}{\protect\numberline{\thealgorithm}{\ignorespaces #1}}}%
\toprule
\textbf{\fname@algorithm~\thealgorithm}\ #2\par % Caption
\midrule
}
\makeatother
\begin{document}
\listofalgorithms
\section{First section}
\lipsum[1-3]
\begin{figure}[ht]
\algcaption{First algorithm}\label{first-alg}%
\begin{algorithmic}[1]
\Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
\State $r\gets a\bmod b$
\While{$r\not=0$}\Comment{We have the answer if r is 0}
\algstore{euclidA}
\end{algorithmic}
\bottomrule
\bigskip
\algcaption{Second algorithm}\label{second-alg}
\begin{algorithmic}[1]
\algrestore{euclidA}
\State $a\gets b$
\State $b\gets r$
\algstore{euclidB}
\end{algorithmic}
\bottomrule
\end{figure}
\lipsum[2]
\section{Second section}
\lipsum[3]
\begin{algorithm}[t]
\caption{Third algorithm}\label{third-alg}
\begin{algorithmic}[1]
\algrestore{euclidB}
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$\Comment{The gcd is b}
\EndProcedure
\end{algorithmic}
\end{algorithm}
\lipsum[4]
\end{document}
```

Algorithms meant to stick together this way are contained within the same wrapper float (`figure`

in this case) and are separated using `\bigskip`

(which roughly match the space between other floats). Using `float`

to create an `algorithm`

float (rather than using the `algorithm`

package) is merely so one can tap into things like a `\listofalgorithms`

as well as an `algorithm`

counter.

Additional packages used in the examples include `lipsum`

(not required) for dummy text and the `ifmtarg`

package (required) to check for an empty argument to `\algcaption`

.

^{*} The `algorithmicx`

bundle provides more advanced features, including the possibility to store/restore `algorithmic`

settings (that were used in the above examples), which is not offered by that of the `algorithms`

bundle.

## Best Answer

In the source code of the

`algpseudocode`

package, look for the definitions of the macros used for typesetting functions and procedures:You can see that some

`\textproc`

macro is used to typeset the name of the function/procedure. For information, that macro is defined (in`algpseudocode`

) as follows,where

`\algnewcommand`

is simply`\newcommand`

with a twist.However, you shouldn't just use

`\textsc`

to typeset function/procedure names in the main text; using`\textproc`

is preferable, from a semantic point of view.