2

I'm using \documentclass{tufte-book} and trying to get a full-width algorithm environment (specifically, using algorithm2e).

Minimum working example:

\documentclass{tufte-book}

\title{Full-width algorithm2e algorithms}

\usepackage{lipsum} % for dummy text only

\usepackage[lined, ruled]{algorithm2e}

\begin{document}

\lipsum[2]

\begin{algorithm}[H]
    \tcp{Main loop}
    \While{not converged}{
        $a = a + 1$ \;
    }
    \caption{A text-width algorithm}
\end{algorithm}

\lipsum[2]

\marginnote[10pt]{This algorithm should be full-width, but isn't}
\begin{fullwidth}
\begin{algorithm}[H]
    \tcp{Main loop}
    \While{not converged}{
        $a = a + 1$ \;
    }
    \caption{A full-width algorithm}
\end{algorithm}
\end{fullwidth}

\lipsum[2]

\end{document}

Which renders:

Screenshot of rendered output from minimum working example

In the algorithm2e.sty source-code, I found the dimension algowidth defined about half way through the document.

%[snip]
\newdimen\algowidth%
%[snip]

So I've tried adjusting this length using \setlength{\algowidth}{XXX} in my example, but it doesn't seem to have any effect.

  • How can I achieve full-width algorithm2e algorithm blocks with tufte-latex?
  • Bonus marks if algorithm* can be adjusted to be full-width by default.
  • Extra bonus marks if the algorithm caption can also be moved to hang in the margin, as is the style with tufte-latex full width figures and tables.

Possibly related questions that don't seem to answer this:

1

This might not be the most ideal solution since you loose the floating behaviour of the algorithmby enclosing it in a minipage, but you nevertheless already deactivated the float mechanism by adding [H]...

enter image description here

\documentclass{tufte-book}

\title{Full-width algorithm2e algorithms}

\usepackage{lipsum} % for dummy text only

\usepackage[lined, ruled]{algorithm2e}

\newenvironment{widealgorithm}{\begin{fullwidth}
\begin{minipage}{\linewidth}
\begin{algorithm}[H]}{\end{algorithm}
\end{minipage}
\end{fullwidth}}

\begin{document}

\lipsum[2]

\begin{algorithm}[H]
    \tcp{Main loop}
    \While{not converged}{
        $a = a + 1$ \;
    }
    \caption{A text-width algorithm}
\end{algorithm}

\lipsum[2]


\begin{fullwidth}
\begin{minipage}{\linewidth}
\begin{algorithm}[H]
    \tcp{Main loop}
    \While{not converged}{
        $a = a + 1$ \;
    }
    \caption{A full-width algorithm}
\end{algorithm}
\end{minipage}
\end{fullwidth}

\lipsum[2]

\begin{widealgorithm}
    \tcp{Main loop}
    \While{not converged}{
        $a = a + 1$ \;
    }
    \caption{A full-width algorithm}
\end{widealgorithm}


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