逐字环境无缩进

逐字环境无缩进

我想停用逐字环境的缩进,以便所有内容的左边距都相同。

\documentclass{article}
\usepackage{verbatimbox}
 \makeatletter
 \setcounter{VerbboxLineNo}{-1}
 \renewenvironment{verbnobox}{%
  %  \setcounter{VerbboxLineNo}{-1}%
   \let\my@par\par%
   \def\verbatim@processline{%
  {\addtocounter{VerbboxLineNo}{1}%
 \@tmp\setbox0=\hbox{\@tmp\the\verbatim@line}%
 \hsize=\wd0 \the\verbatim@line\my@par}}%
 \verbatim\verbbox@inner%
   }
  {%
  \endverbatim%
  \global\def\@tmp{}%
    \addtocounter{VerbboxLineNo}{-1}%
   }
  \makeatother
  \begin{document}
   \def\tmp{\makebox[0pt][r]{\scriptsize\theVerbboxLineNo\ \smash{%
    \rule[-1.4\dp\strutbox]{1pt}{1.4\baselineskip}}\ }\small}
  NO INDENT SHOULD BE AFTER THIS 
  \begin{verbnobox}[\tmp]
   ADASFASFASF
  \end{verbnobox}
  NO INDENT SHOULD BE AFTER THIS 
 \begin{verbnobox}[\tmp]
  AFASDASFASGASDF

   \end{verbnobox}
   RESET LINE NUMBERS
  \setcounter{VerbboxLineNo}{-1}
  \begin{verbnobox}[\tmp]
   Reset Line Numbers should appear here
   \end{verbnobox}
   \end{document}

答案1

只需从逐字内容中删除前导空格即可解决问题。

通常情况下,LaTeX 代码中的前导空格会被忽略。但在样式环境中情况并非如此verbatim,空格会​​按字面意思解释。

\documentclass{article}
\usepackage{verbatimbox}
 \makeatletter
 \setcounter{VerbboxLineNo}{-1}
 \renewenvironment{verbnobox}{%
  %  \setcounter{VerbboxLineNo}{-1}%
   \let\my@par\par%
   \def\verbatim@processline{%
  {\addtocounter{VerbboxLineNo}{1}%
 \@tmp\setbox0=\hbox{\@tmp\the\verbatim@line}%
 \hsize=\wd0 \the\verbatim@line\my@par}}%
 \verbatim\verbbox@inner%
   }
  {%
  \endverbatim%
  \global\def\@tmp{}%
    \addtocounter{VerbboxLineNo}{-1}%
   }
  \makeatother
  \begin{document}
   \def\tmp{\makebox[0pt][r]{\scriptsize\theVerbboxLineNo\ \smash{%
    \rule[-1.4\dp\strutbox]{1pt}{1.4\baselineskip}}\ }\small}
  NO INDENT SHOULD BE AFTER THIS 
  \begin{verbnobox}[\tmp]
ADASFASFASF
  \end{verbnobox}
NO INDENT SHOULD BE AFTER THIS 
 \begin{verbnobox}[\tmp]
AFASDASFASGASDF

   \end{verbnobox}
   RESET LINE NUMBERS
  \setcounter{VerbboxLineNo}{-1}
  \begin{verbnobox}[\tmp]
Reset Line Numbers should appear here
   \end{verbnobox}
   \end{document}

在此处输入图片描述

相关内容