我知道我可以使用\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}