![algorithm2e 中的可用宽度](https://linux22.com/image/296379/algorithm2e%20%E4%B8%AD%E7%9A%84%E5%8F%AF%E7%94%A8%E5%AE%BD%E5%BA%A6.png)
我想在里面使用环境algorithm2e
,但结果发现它太宽了。我尝试绘制一些框来查看宽度,结果发现\textwidth
在算法中它太大了。framed
但是环境遵循正确的大小。
我的问题是:如何访问算法区域中的可用宽度?
以下是 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}
答案1
环境algorithm
会增加其内容的左边距和右边距,因此您必须从中减去它们textwidth
:
\documentclass[a4paper,draft]{article}
\usepackage[utf8]{inputenc}
\usepackage[ruled]{algorithm2e}
\usepackage{framed}
\begin{document}
\begin{algorithm}[h]
\begin{framed}
something in a framed environment
\end{framed}
Some text… Some text… Some text… Some text… Some text… Some text… Some text… Some text…Some text… Some text… Some text… Some text… \\[1ex]
\fbox{\parbox{\dimexpr\textwidth-2\algomargin\relax}{something with textwidth }}\\[1ex]
\caption{Some algorithm.}
\end{algorithm}
\end{document}