General ⇒ How to continue displaying an algorithm if it is too long?
How to continue displaying an algorithm if it is too long?
Hi, I have a situation that an algorithm has too many lines (too long), which can't be fitted into one page. Then the remainder of the algorithm couldn't be displayed in the next page so some reason. I am wondering how to resolve this issue?
ps. I am still using the same PhD thesis template (Cambridge version 2007), may be it is the cause of the problem?
cheers
ps. I am still using the same PhD thesis template (Cambridge version 2007), may be it is the cause of the problem?
cheers
- Stefan Kottwitz
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
How to continue displaying an algorithm if it is too long?
Hello,
there are several packages for this purpose, such as
minimal working example of your code, which shows the problem.
Stefan
there are several packages for this purpose, such as
algorithm
, algorithm2e
, algorithmic
, algorithmicx
, and more. We cannot now how you are doing it, so it's hard to guess what may be the issue for you. So, please post a 
Stefan
LaTeX.org admin
How to continue displaying an algorithm if it is too long?
Here it is.Stefan_K wrote:Hello,
please post aminimal working example of your code, which shows the problem.
Stefan
Code: Select all
{\scriptsize
\begin{algorithm}
\caption{Construct relational tables}
\label{alg3}
\begin{algorithmic}[1]
\REQUIRE a set of data item clusters $C$
\ENSURE a relational table with all data items aligned
\STATE Set $tempItemSet$ and $currentRowItemSet$ to $\{\}$
\FOR{every cluster $c_i \in C$ for $i = 1, 2,..., n$}
\STATE Sort the data items in $c_i$ from top to bottom
\ENDFOR
\STATE Sort the clusters in $C$ from left to right
\FOR{every cluster $c \in C$}
\STATE Add $Item_i^1 \in c$ to $tempItemSet$ for $i = 1, 2,..., n$
\ENDFOR
\REPEAT
\STATE Separate data items in $tempItemSet$ into groups \{$g_1, g_2,..., g_m$\}, based on their record numbers
\IF{$g_i$ has the majority of data items in $tempItemSet$}
\STATE Move data items in $g_i$ to $currentRowItemSet$
\ELSE \IF{the first data item in $g_i$ has the left-most position among the first data items in the remaining groups}
\STATE Move data items in $g_i$ to $currentRowItemSet$
\ENDIF
\ENDIF
\STATE Fill blanks into the positions left by the data items in $tempItemSet$ for $currentRowItemSet$
\IF{there is a row above $currentRowItemSet$}
\FOR{every remaining data item $i \in tempItemSet$ and $j \in currentRowItemSet$}
\IF{$i$ matches any previous data item based on record number at its corresponding column}
\STATE Add a new row under the least matched data item and put $i$ in its corresponding column
\ELSE \IF{$i$ matches any previous data item based on record number at that row}
\STATE Put $i$ in its corresponding column of the row
\ENDIF
\ENDIF
\IF{$j$ matches any previous data item based on record number at that row}
\STATE Put $j$ in its corresponding column of the row
\ENDIF
\ENDFOR
\ENDIF
\FOR{every cluster $c \in C$}
\IF{$Item_i^j$ exists in $currentRowItemSet$ or $tempItemSet$ = \{\}}
\STATE Add $Item_i^{j+1}$ to $tempItemSet$
\ENDIF
\ENDFOR
\UNTIL{$tempItemSet = \{\}$}
\end{algorithmic}
\end{algorithm}
}
\usepackage{algorithm}
.How to continue displaying an algorithm if it is too long?
This is nodaiyue wrote:Here it is.Stefan_K wrote:please post aminimal working example of your code, which shows the problem.

Regards
site moderator & package author
How to continue displaying an algorithm if it is too long?
Sry for the minimal working example, as there a separated style class file, and a main tex file along with several individual tex files as chapters in the thesis. It might be difficult to pull up a minimal working example to reproduce the problem.
By Googling the algorithm split problem, I have started to use
After I compiled the main tex file, I got the following error:
I was using
There was no problem (can refer to my last post for the algorithm).
How to resolve the issue?
Thanks
By Googling the algorithm split problem, I have started to use
\algstore{myalg}
. But it requires algorithmicx
, so I pull up the following code in order to use it.Code: Select all
\usepackage{algorithm}
\usepackage{algorithmicx}
\algnewcommand\algorithmicinput{\textbf{Input:}}
\algnewcommand\algorithmicoutput{\textbf{Output:}}
Code: Select all
! Undefined control sequence.
l.219 \REQUIRE
\usepackage[noend]{algorithmic}
\usepackage{algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input: }}
\renewcommand{\algorithmicensure}{\textbf{Output: }}
There was no problem (can refer to my last post for the algorithm).
How to resolve the issue?
Thanks
- Johannes_B
- Site Moderator
- Posts: 4182
- Joined: Thu Nov 01, 2012 4:08 pm
How to continue displaying an algorithm if it is too long?
This seems to be a duplicate to TeX.SX.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
- Stefan Kottwitz
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
How to continue displaying an algorithm if it is too long?
Regarding your referencing question in the cross-post: you can place
\label{...}
and use \ref{...}
as usual. Complete example, compile twice to get the ?? replaced:Code: Select all
\documentclass{article}
\usepackage{dsfont}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{mathtools}
\newcommand{\minbox}[2]{%
\mathmakebox[\ifdim#1<\width\width\else#1\fi]{#2}}
\newcommand{\Let}[2]{\State $ \minbox{1em}{#1} \gets #2 $}
\algnewcommand{\Local}{\State\textbf{local variables: }}
\begin{document}
Note, the while loop ends at line \ref{endwhile}.
\begin{algorithm}
\caption{Mandelbrot set}
\label{alg:mandelbrot}
\begin{algorithmic}[1]
\Require{$c_x, c_y, \Sigma_{\max} \in \mathds{R},
\quad i \in \mathds{N}, \quad i_{\max} > 0,
\quad \Sigma_{\max} > 0$}
\Function{mandelbrot}{$c_x, c_y, i_{\max},
\Sigma_{\max}$}
\Local{$x, y, x^\prime, y^\prime, i, \Sigma$}
\Let{x, y, i, \Sigma}{0}
\Comment{initial zero value for all}
\While{$\Sigma \leq \Sigma_{\max}$
and $i < i_{\max}$}
\Let{x^\prime}{x^2 - y^2 + c_x}
\Let{y^\prime}{2xy + c_y}
\Let{m}{x^\prime}
\Let{y}{y^\prime}
\Let{\Sigma}{x^2 + y^2}
\EndWhile\label{endwhile}
\If{$i < i_{\max}$}
\State \Return{$i$}
\EndIf
\State\Return{0}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}
\EndIf
and such can hardly be shortened, ay they belong to the syntax. You need to close blocks.LaTeX.org admin
How to continue displaying an algorithm if it is too long?
Sry, I didn't know the two sites are related. So I tried my luck and posted on both sites.Johannes_B wrote:This seems to be a duplicate to TeX.SX.
How to continue displaying an algorithm if it is too long?
The thing is when I was usingStefan_K wrote:\EndIf
and such can hardly be shortened, ay they belong to the syntax. You need to close blocks.
algorithmic
, there seems to be no end if
and such appears. So I was wondering how to turn such thing off.- Stefan Kottwitz
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
How to continue displaying an algorithm if it is too long?
Just post a link to the other site too, when you make a crosspost. Same for TeX StackExchange, add a link to the other post - I can say this also as a moderator there.
The link shall prevent double work, such as two people working out the same solution. So they would be informed.
Completely unrelated: in that case people may blindly create similar solutions even when the issue is already solved on the other site. On an unrelated site they won't know. But a link will fix any crosspost-issue.
Stefan
The link shall prevent double work, such as two people working out the same solution. So they would be informed.
That's actually a benefit. So people might notice, and don't do work twice and waste time.daiyue wrote:Sry, I didn't know the two sites are related.
Completely unrelated: in that case people may blindly create similar solutions even when the issue is already solved on the other site. On an unrelated site they won't know. But a link will fix any crosspost-issue.
Stefan
LaTeX.org admin