1

When using the revtex4-2 document class with the twocolumn option, the algorithmic environment of the algpseudocodex package has a right margin which extends too far. How do I fix this so the right margin aligns with that of body text? MWE below.

\documentclass[twocolumn,nobalancelastpage]{revtex4-2}
\usepackage{algpseudocodex}

\begin{document}
See the following lines of code.
The right margin seems to go further than that of body text.
See the following lines of code.
The right margin seems to go further than that of body text.

\begin{algorithmic}
    \State A long first statement to demonstrate where statements linewrap.
    \State A short second statement.
    \Comment{Short comment.}
    \LComment{Long comment.}
\end{algorithmic}

\end{document}

The nobalancelastpage class option is there just so I can compare the margins of the body text and the algorithmic environment. Screenshot of MWE output below.

Output of MWE.

The problem goes away if I change one of the following:

  • revtex4-2 to article
  • twocolumn to onecolumn
  • algpseudocodex to algpseudocode (and delete \LComment{Long comment.})
2
  • 1
    As a dirty hack, you could warp \noindent\begin{minipage}{.96\linewidth} ... \end{minipage} around the algorithm Commented Jun 2, 2023 at 15:33
  • Thanks @samcarter_is_at_topanswers.xyz, this works even inside an algorithm environment (which usually wraps around the algorithmic environment)
    – Tim Chan
    Commented Jun 2, 2023 at 22:00

1 Answer 1

1

Quick and dirty hack: use a minipage around the algorithm to make the line shorter:

\documentclass[twocolumn,nobalancelastpage]{revtex4-2}
\usepackage{algpseudocodex}

\begin{document}
See the following lines of code.
The right margin seems to go further than that of body text.
See the following lines of code.
The right margin seems to go further than that of body text.

\noindent\begin{minipage}{\dimexpr\linewidth-\parindent}
\begin{algorithmic}
    \State A long first statement to demonstrate where statements linewrap.
    \State A short second statement.
    \Comment{Short comment.}
    \LComment{Long comment.}
\end{algorithmic}
\end{minipage}

\end{document}

enter image description here

You must log in to answer this question.

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