1

I would like to deactivate the indent for the verbatim environment, such that left margin is the same for everything.

\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}
3
  • Welcome to TeX.SX! I have removed the thanks as well as your name since it is displayed in the lower right corner of your post anyway.
    – moewe
    Commented Sep 9, 2015 at 17:24
  • 2
    Your problem is that you have leading spaces in your verbnobox environments. They are echoed in the output Commented Sep 9, 2015 at 17:27
  • Crosspost
    – Johannes_B
    Commented Sep 11, 2015 at 14:34

1 Answer 1

3

Simply removing the leading space from your verbatim content takes care of the problem.

Normally, leading spaces in LaTeX code are ignored. But that is not the case in verbatim style environments, where spaces are interpreted literally.

\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}

enter image description here

2
  • @ Steven thanks for the reply. But I meant it differently. Everything should have the same margin. Now, the numbers are slightly shifted to the left. I was hoping for this: HEADLINE 1 1 some stufff 2 dafasf 3 aasfafas HEADLINE 2 1 some stufff 2 dafasf 3 aasfafas hope this helps :)
    – user87544
    Commented Sep 11, 2015 at 16:45
  • 1
    @Arjen Change \makebox[0pt][r] simply to \makebox. Commented Sep 11, 2015 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .