2

It seems like there is no option for specifying that, like a hack for verbatim I found on tex.stackexchange:

\usepackage{etoolbox}%
\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother

\begin{alltt} skips a line before en after its content, how can I remove this ? I tried to use the code below with @alltt instead of @verbatim but it doesn't work.

Indeed I am using knitr which places code input in alltt environment, there may be some other knitr specific solutions too I might be interested in.

MWE:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{alltt}
\usepackage{etoolbox}%

\begin{document}

Few words
\begin{alltt}
alltt words
\end{alltt}
something else

\begin{verbatim}
verbatim words
\end{verbatim}
and with the hack:

\makeatletter
\preto{\@verbatim}{\topsep=0pt \partopsep=0pt}
\makeatother

\begin{verbatim}
verbatim words
\end{verbatim}
the end

\end{document}

alltt and verbatim

  • Does knitr not use \begin{document} \end{document}? If it does, please provide the rest of your MWE Perhaps upload an image of output? – A Feldman May 23 '16 at 12:59
  • knitr automatically produces a .tex file form the .Rnw; it's not directly related to my question but I thought there might be knitr options to change that. – ClementWalter May 23 '16 at 13:30
2

There is no \@alltt but like verbatim (and most latex display constructs) alltt is a trivlist so the same settings apply, you just need

\preto{\alltt}{\topsep=0pt \partopsep=0pt}
  • ok, not an expert of tex elements, but works like a charm, thanks! (trivlist, didn't even know what it is!). Is there a way to remove only the first line break and to keep the final one ? – ClementWalter May 23 '16 at 16:25

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.