Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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.

share|improve this answer
    
awesome, \dfrac works great, thanks a lot, I'll look into this amsmath package –  SinistraD May 31 '11 at 22:07
add comment

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}

share|improve this answer
    
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 –  SinistraD May 31 '11 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. –  Gonzalo Medina May 31 '11 at 22:38
    
You're right this work great. It messes up the code a bit but has a good result. Thanks a lot –  SinistraD May 31 '11 at 23:09
1  
You're welcome! –  Gonzalo Medina May 31 '11 at 23:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.