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.

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}
  • 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? – ClementWalter Oct 14 '16 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} – David Carlisle Oct 14 '16 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. – ClementWalter Oct 14 '16 at 17:44
  • @clemlaflemme sigh, you could have said:-) I'll add something to the answer – David Carlisle Oct 14 '16 at 17:46
  • 1
    @clemlaflemme I added the saving of the end code, sorry, can't help with knitr – David Carlisle Oct 18 '16 at 8:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.