3

I've just starting using LaTeX (today), because I wanted a professional way to format some pseudocodes, needed for a paper. So this might be a lame question, but can't find anything relevant.

My problem is that when using the \frac command with algorithmicx package, the constant height of the row makes the fraction small, hard to read. Here is an example:

Is there a way to enlarge the row height and those parts which got shrunk? I also noticed, that other writer use the / operator instead of \fract, but I would rather not, I have pretty long formulas, and this would make them harder to read, and not because of the font size. I don't need constant row height, but a readable code.

2 Answers 2

1

If you load amsmath you can write \dfrac{A}{\sqrt{h}}; otherwise the almost equivalent code {\displaystyle\frac{A}{\sqrt{h}} can be used. But amsmath has many other features that come in handy when the math in the document is more than a couple of simple formulas.

1
  • awesome, \dfrac works great, thanks a lot, I'll look into this amsmath package Commented May 31, 2011 at 22:07
3

If you want to have even more vertical space between particular rows, you can break the algorithm, introduce the desired space, and then restore the algorithm, as explained in the documentation for algorithmx (5.2 Breaking up an algorithm). A little example (notice the extra vertical space surrounding the second row):

\documentclass{book}
\usepackage{amsmath}
\usepackage{algorithmicx}

\begin{document}

\begin{algorithmic}[1]
  \State $sum\gets 0$
  \algstore{bkbreak}
\end{algorithmic}\vskip0.3em
\begin{algorithmic}[1]
  \algrestore{bkbreak}
  \State $i\gets \dfrac{A}{\sqrt{h}}$
  \algstore{bkbreak}
\end{algorithmic}\vskip0.3em
\begin{algorithmic}[1]
  \algrestore{bkbreak}
  \State $sum\gets sum+i$
  \State $i\gets i+1$
\end{algorithmic}

\end{document}

EDIT: And here's the same example algorithm but with a caption:

\documentclass{book}
\usepackage{amsmath}
\usepackage{algorithmicx,algorithm}

\begin{document}

\begin{algorithm}
\caption{A test algorithm}
\begin{algorithmic}[1]
  \State $sum\gets 0$
  \algstore{bkbreak}
\end{algorithmic}\vskip0.3em
\begin{algorithmic}[1]
  \algrestore{bkbreak}
  \State $i\gets \dfrac{A}{\sqrt{h}}$
  \algstore{bkbreak}
\end{algorithmic}\vskip0.3em
\begin{algorithmic}[1]
  \algrestore{bkbreak}
  \State $sum\gets sum+i$
  \State $i\gets i+1$
\end{algorithmic}
\end{algorithm}

\end{document}

3
  • Good idea, but unfortunately I can't do that. It draws separating lines (just like in the example) and I like those lines for the title/ending, don't want to dispose of them, also I have other reasons as well. Anyway +1 for the idea Commented May 31, 2011 at 22:31
  • 1
    @SinistraD: but using only one algorithm environment you can get only the lines for the caption and at the ending... see (in a few minutes) my updated example. Commented May 31, 2011 at 22:38
  • You're right this work great. It messes up the code a bit but has a good result. Thanks a lot Commented May 31, 2011 at 23:09

You must log in to answer this question.

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