fancyvrb 和 \overfullrule

fancyvrb 和 \overfullrule

我知道我可以使用\overfullrule=5pt黑色标记来标记过满的行,但使用包Verbatim中的环境fancyvrb不会标记过满的行。例如,

\documentclass{article}
\usepackage{fancyvrb}

\overfullrule=5pt

\begin{document}
\mbox{Overfull line marked without using the Verbatim environment from the fancyvrn package.}

\begin{Verbatim}
Overfull line not marked using the Verbatim environment from the fancyvrb package.
\end{Verbatim}
\end{document}

注意:我知道我可以使用BVervatim环境来标记超额的行,但它会改变我文档中的所有代码布局。

是否可以使用Verbatim环境并标记超额的线条?

答案1

在此处输入图片描述

\documentclass{article}
\usepackage{fancyvrb}

\overfullrule=5pt
\makeatletter

\let\oldFancyVerbFormatLine\FancyVerbFormatLine
\def\FancyVerbFormatLine#1{%
\setbox0\hbox{\oldFancyVerbFormatLine{#1}}%
\ifdim\wd0>\textwidth
\hbox{\box\z@\vrule\@width\overfullrule}%
\else
\box\z@
\fi} 
\makeatother


\begin{document}
\mbox{Overfull line marked without using the Verbatim environment from the fancyvrn package.}


\begin{Verbatim}
Overfull line not marked using the Verbatim environment from the fancyvrb package.
short line
Overfull line not marked using the Verbatim environment from the fancyvrb package.
\end{Verbatim}



\end{document}

相关内容