3

My algorithms takes up too much space in the document. I would like to do 2 things:

  • set the width bigger, so the lines which does not fit to a single line would do
  • remove lines with end keywords (i.e. closing tags or whatever they are called)

Are these things possible?

Sorry if these question are lame, but I'm pretty new to TeX, I use LaTeX only for algorithms, I'm writing my document in another format.

UPDATE: Example:

Complete document:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\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}

Here is the result, corrected with red, on what I would like to be changed (with MS Paint, yeah I do have some epic Paint skillz right?):

Comments are in Hungarian, don't mind that

3
  • Can you post an example document so we can see what you're working with? Commented Jun 17, 2011 at 19:17
  • I did. Hope that helps you help me. Commented Jun 17, 2011 at 19:39
  • Found a solution, see below. Commented Jun 17, 2011 at 20:29

1 Answer 1

2

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 ends, 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}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .