Essentially, it's a matter of page geometry. \usepackage{fullpage}
works, for instance, but you can probably also fool around with the geometry
package to get a more customizable effect.
Also, see One inch margins and the geometry package.
As for the second point about removing the end
s, section 4 of algorithmicx
's documentation describes customizing blocks.
Edit: Here's an example.
If you add \algnotext{EndFor}
, For
blocks will print no end
. You can then apply this to EndIf
and anything else you need.
\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath,fullpage}
\algnotext{EndFor}
\algnotext{EndIf}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Function {NMS3D}{$T : array[1..w, 1..h, 1..d], n: int$}
\State \Comment $(2 n +1) \times (2 n +1) \times (2 n +1)$ szomsz\'eds\'gban keress\"uk a lok\'alis maximumokat
\State label \textbf{mainloop:}
\ForAll {$(i, j, k) \in \{ n, 2n+1, ... \}^3 \cap [1..w - n] \times [1..h - n] \times [1..d - n] $}
\State \textbf{initialize:} $(i_{max}, j_{max}, k_{max}) \gets (i, j, k)$
\ForAll {$(i_2, j_2, k_2) \in [i, i+n] \times [j, j+n] times [k, k+n]$}
\If {$T[i_2, j_2, k_2] > T[i_{max}, j_{max}, k_{max}]$}
\State $(i_{max}, j_{max}, k_{max}) \gets (i_2, j_2, k_2)$
\EndIf
\EndFor
\ForAll {$(i_2, j_2, k_2) \in [i_{max}-n, i_{max}+n] \times [j_{max}-n, j_{max}+n] \times [k_{max}-n, k_{max}+n]
- [i, i+n] \times [j, j+n] \times [k, k+n]$}
\If {$T[i_2, j_2, k_2] > T[i_{max}, j_{max}, k_{max}]$}
\State \textbf{continue} mainloop
\State \Comment a maximum jel\"olt t\'ul k\"ozel van egy m\'asik maximumhoz, elvetj\"uk
\EndIf
\EndFor
\State $list_{max} \stackrel{add}{\longleftarrow} (i_{max}, j_{max}, k_{max})$
\EndFor
\State \textbf{return} $list_{max}$
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}
You need to remove
\usepackage{algorithmicx}
and use the following in your preamble:
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
The reason for this is because the algorithmicx
package provides (in addition to just defining the algorithmic
environment through algorithmicx.sty
) a bundle of style files with predefined macros (like \Procedure
, \Comment
, etc), including algpseudocode.sty
. See the package documentation (section 2.1 The package for more on this).
One thing the algorithmicx
package does not define is the floating algorithm
environment. That is provided by the algorithms
bundle. Hence the requirement to include that as well.
Best Answer
I've stumbled upon this problem before, and found that merely making the command robust fixes it: