4

I've been trying to insert the code to my LaTeX document. I used this piece of code:

\begin{lstlisting}[label={lst:rws}, captionpos={bottom}, caption={Pseudo-code of RWS Selection}]
r = Random(); /* Uniformly distributed random number in [0,1] */
sum = 0;
for (i = 1; i < population.size; i++)
    sum += individual(i).probabilityOfSelection;
    if (sum >= r)
        select(i)
\end{lstlisting}

However I get duplicated caption at the top of the listing and also at the bottom. If I don't use captionpos={bottom} I get caption on top of the listing. Any idea what might be causing it? Here's what I get:

Duplicate description

Thanks

6
  • 3
    Use b instead of bottom. This looks like a bug, apparently, bottom is interpreted both and leads to top and bottom caption
    – user31729
    Apr 7, 2016 at 20:21
  • Yeah it worked thanks. I would have never thought that it would interpret bottom as bottom
    – MichaelDD
    Apr 7, 2016 at 20:24
  • very interesting bug ;) Do you want to report it @ChristianHupfer or shall I do it? Apr 7, 2016 at 20:29
  • @StefanPinnow: Go ahead. You answered the question, now it's your job :-P
    – user31729
    Apr 7, 2016 at 20:48
  • 1
    @ChristianHupfer, done ;) Apr 7, 2016 at 20:53

1 Answer 1

4

If you just provide captionpos={b} - as it is stated in the manual - it is working fine.

\documentclass[border=2mm]{standalone}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[
    label={lst:rws},
    captionpos={b},
    caption={Pseudo-code of RWS Selection}
]
r = Random(); /* Uniformly distributed random number in [0,1] */
sum = 0;
for (i = 1; i < population.size; i++)
    sum += individual(i).probabilityOfSelection;
    if (sum >= r)
        select(i)
\end{lstlisting}
\end{document}

image showing the result of above code

(Nonetheless it is the question, if the "non-valid" value shouldn't raise an error ...)

1
  • Oh dear, thank you. It's so weird that it doesn't notify you that "bottom" is invalid value
    – MichaelDD
    Apr 7, 2016 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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