1

The environment alltt skips a line before and after its use. Is there a way to modify this behaviour to avoid these empty lines ?

*** Edit I tried to get inspired by a similar post about figure but I am a noob and don't really understand how to modify the answer.

1 Answer 1

3

Like most latex displays it is a list and so has \topsep spacing above it (note thiis is stretchable vertical space not really a blankline) You can set it to 0 eiether inline or in a \newenvironment definition

\documentclass{article}
\usepackage{alltt}
\begin{document}

xxxxxxxxxxxxxxxxxxxx
{\setlength\topsep{0pt}\begin{alltt}
one two three
four five six
\end{alltt}}%
xxxxxxxxxxxxxxxxxxxxxxx
\end{document}

to redefine alltt to always do this you can use

\let\oldalltt\alltt
\let\endoldalltt\endalltt
\renewenironment{alltt}{\setlength\topsep{0pt}\oldalltt}{\endoldalltt}
8
  • thanks, but this affect all the list-type environment then? is there a way to redefine the alltt environment (with \renewenvironment like in the mentioned question) to alter only alltt? Oct 14, 2016 at 17:32
  • @clemlaflemme as above it only affects this instance (note the {} group around the setting. simplest definition if you want lots of these is just \newenvironment{alltt2}{\setlength\topsep{0pt}\alltt}{\endalltt} Oct 14, 2016 at 17:40
  • the main thing is that I use knitr which produce .tex with alltt environments. That's why I'd like to redefine this environment, and not define to define a new one with another name. Oct 14, 2016 at 17:44
  • @clemlaflemme sigh, you could have said:-) I'll add something to the answer Oct 14, 2016 at 17:46
  • 1
    @clemlaflemme I added the saving of the end code, sorry, can't help with knitr Oct 18, 2016 at 8:29

You must log in to answer this question.

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