I wanted to use an environment inside an algorithm2e
and it turned out, that it is too wide. I tried to draw some boxes to see the width, and it turned out that \textwidth
is too large inside the algorithm. The framed
environment however adheres to the correct size.
My question is: How can I access the available width in the algorithm area?
Here is a MWE:
\documentclass[a4paper,draft]{article}
\usepackage[ruled]{algorithm2e}
\usepackage{framed}
\begin{document}
\begin{algorithm}[h]
\begin{framed}
something in a framed environment
\end{framed}
\fbox{\parbox{\textwidth}{
something with textwidth
}}
\caption{Some algorithm.}
\end{algorithm}
\end{document}
Best Answer
The
algorithm
environment increases left and right margins of its contents, so you have to substract them fromtextwidth
: