3

I have a simple code that inserts a complex layout for figures and I would like to randomly alternate the position options (for instance, alternating between top and bottom positioning: begin{figure}[t] / [b]). So far, I have been doing this:

\documentclass[11pt, a4paper, frenchb]{article}
\usepackage{polyglossia}
\usepackage[first=0, last=1, quiet]{lcg}

\begin{document}
rand sequence: \rand\arabic{rand}\rand\arabic{rand}
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}

\ifthenelse{\equal{\rand\arabic{rand}}{1}}
        {align figure to TOP}{align figure to BOTTOM}

\end{document}

but I've got an Undefined control sequence. How can I compare the value returned by the lcg \rand to something common so I can have my figures evenly inserted at the top or bottom across pages.

4

You need to place the \random generation outside the comparison:

\documentclass{article}
\usepackage{xifthen}
\usepackage[first=0, last=1, quiet]{lcg}

\begin{document}
rand sequence: \rand\arabic{rand}\rand\arabic{rand}%
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}%
\rand\arabic{rand}\rand\arabic{rand}\rand\arabic{rand}

\rand\ifthenelse{\equal{\arabic{rand}}{1}}
        {align figure to TOP}{align figure to BOTTOM}

\end{document}

If you're using pdfTeX, the following doesn't require any packages:

\documentclass{article}

\begin{document}
rand sequence: \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2
  \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2 \pdfuniformdeviate2

\ifnum\pdfuniformdeviate2=0
  align figure to TOP
\else
  align figure to BOTTOM
\fi

\end{document}
| improve this answer | |

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.