I defined a new environment, similar (but not equal) to listings
:
\documentclass{ltxdoc}
\usepackage{lipsum}
\newenvironment{lines}
{\par\begingroup\nobreak
\vspace{3pt}\parindent0pt\hrule\kern5pt
\nobreak\obeylines\everypar{\strut}\endgroup}
{\par\begingroup\nobreak
\vspace{3pt}\parindent0pt\hrule\kern5pt
\nobreak\obeylines\everypar{\strut}\endgroup%
\noindent%
}
\begin{document}
\lipsum[1]
\begin{lines}
Some nifty code and stuffz
\end{lines}
\lipsum[2]
\end{document}
Why does my \noindent
keep a small space before the text? Did I miss something?
Best Answer
If you use
\noindent
you will almost always get this behaviour. The space is an inter word space being typeset from the end of line after the environment.You can avoid the problem by using
\ignorespacesafterend
but that is papering over the cracks. The error is using\noindent
which has started horizontal mode prematurely which is why the end of line is typeset as a space. LaTeX environments never do this. You should define the environment usingtrivlist
then the environment will end in vertical mode, but if no blank line follows indentation will be suppressed (it is actually removed using\lastbox
rather than not being added using\noindent
.)Something like this, adjust lengths to suit.