boxruled 格式算法文本溢出

boxruled 格式算法文本溢出

我有一个算法,它实际上是一串长语句,我希望它放在一个框内,但下面的代码却导致自动换行错误。有人知道为什么吗?

\documentclass[a4paper,10pt]{article}
\usepackage{algorithm2e}
\begin{document}
\RestyleAlgo{boxruled}
\begin{algorithm}
\scriptsize    
\begin{enumerate}
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\end{enumerate}
\caption{A caption}
\end{algorithm}
\end{document}

我试过把它放进去miniboxes\vbox但没什么用

答案1

\addtolength\linewidth{-4ex}已修订。需要在环境内添加该行algorithm。起初,我认为调整是\leftmargini和/或的倍数\labelsep,但在此 MWE 中进一步测试证明这种信念是错误的。相反,对的固定调整\linewidth似乎效果最好。

\documentclass[a4paper,10pt]{article}
\usepackage{algorithm2e}
\begin{document}

This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj

\RestyleAlgo{boxruled}
\begin{algorithm}
\addtolength\linewidth{-4ex}
\scriptsize    
\begin{enumerate}
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\end{enumerate}
\caption{A caption}
\end{algorithm}

\leftmargini=3\leftmargini
\labelsep=6\labelsep
\begin{algorithm}
\addtolength\linewidth{-4ex}
\scriptsize    
\begin{enumerate}
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjjj
\item This is a long text that overflow the box jjjj jjjjjjjjjjjjj jjjjjjjjjjjj jjjjjjjjjj jjjjjj jjjjj jjjj jjjj jjjjjjj jjjj jjjjjj jjjjjjjjj jjjjj jjjj jjjjj jjjjjjj jjjjjj jjjjjjjjjjj j jjjjjjjj j j jjjjjjjj jjjjj j jj jjjjjjjjjj jjjj jjjj jjjjjjj jjjjjjjj jjjjjjjjj jjjjjjjjj jjjj jjjjjjj jjjjjjjj j jjjj jjjj jjjj j j  jjjjjjj jjj jjjjj jjjjjjjj jj jjjj jjj j jjjjjjj
\end{enumerate}
\caption{A caption}
\end{algorithm}
\end{document}

在此处输入图片描述

相关内容