基于 \rand 值比较的条件结构

基于 \rand 值比较的条件结构

我有一段简单的代码,用于插入复杂的图形布局,我想随机交替位置选项(例如,在顶部和底部定位之间交替:begin{figure}[t]/ [b])。到目前为止,我一直在这样做:

\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}

但我有一个Undefined control sequence。我怎样才能将返回的值lcg \rand与某些常见值进行比较,以便我可以将我的数字均匀地插入到页面的顶部或底部。

答案1

您需要放置\random 生成外部比较:

\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}

如果您使用 pdfTeX,则以下内容不需要任何包:

\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}

相关内容