3

I am using a lot the verbatim environments. Today I notice that there is a really disturbing (and too large) space between lines in verbatim environment : enter image description here

How can I remove them ?

EDIT (xelatex): minimal example (you need a monospaced font with u2592 character support)

\documentclass{article}
\usepackage{xltxtra,%
            lmodern,%
            fancyvrb}
\DefineVerbatimEnvironment{VRB}{Verbatim}{baselinestretch=.5}
\begin{document}
\begin{verbatim}
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
\end{verbatim}
\begin{VRB}
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
\end{VRB}
\end{document}
\begin{
3
  • the standard verbatim environment doesn't do anything about baseline spacing, it's just whatever is already set up for the current font size. Jul 13, 2016 at 17:55
  • I'd like to see that myself... it looks disturbing! Can you provide a minimal example that replicates this?
    – Werner
    Jul 13, 2016 at 17:55
  • @Werner My guess is that the ttfamily is perceived differently by the mind than the rmfamily of the font. An optical illusion, if you will. I have been known to reduce the tt font size in my own documents for this reason. Jul 13, 2016 at 18:01

2 Answers 2

1

If you want to completely remove the leading, you need to set \baselineskip to a very large negative dimension, so between every pair of lines \lineskip glue will be inserted; set this to zero and you're done.

\documentclass{article}
\usepackage{fontspec,fancyvrb}
\setmonofont{DejaVu Sans Mono}
\DefineVerbatimEnvironment{VRB}{Verbatim}{%
  formatcom={\baselineskip=-\maxdimen\lineskip=0pt}
}
\begin{document}
\begin{verbatim}
▒▒▒
▒▒▒
▒▒▒
\end{verbatim}
\begin{VRB}
▒▒▒
▒▒▒
▒▒▒
\end{VRB}
\end{document}

Loading lmodern after fontspec is completely useless; also xltxtra is to be avoided, unless you really need its only feature. Load fontspec alone.

enter image description here

0
0

REVISED

u2592 should not need a space change between lines, unless you have previously changed the line spacing, for example with setspace as I show in this MWE. Then, the approach of my original answer should still apply, but the shift may need to be tailored.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{verbatimbox}
\usepackage{fontspec}
\setmainfont{Times New Roman}
\usepackage{setspace}
\doublespacing
\begin{document}
Start
versus
\begin{verbnobox}[\rmfamily\ifnum\value{VerbboxLineNo}>1\relax\vspace{-8pt}\fi]
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
\end{verbnobox}
the end
\end{document}

enter image description here

ORIGINAL

Maybe this would suffice:

\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
Start
\begin{verbatim}
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
\end{verbatim}
versus
\begin{verbnobox}[\ifnum\value{VerbboxLineNo}>1\relax\vspace{-3pt}\fi]
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
((((((((((((((((((((((
\end{verbnobox}
the end
\end{document}

enter image description here

3
  • I missed to specify in the minimal example that I am working with xelatex (even if it is written in the title). Your example, with xelatex, produce... nothing, I have a blank page...
    – krshk
    Jul 13, 2016 at 18:35
  • --------- EDIT --------- I replaced the rmfamily by ttfamily and it seems to work. So I try another question : do you think it is possible to do this with the fancyvrb package which allow me to use commands inside a verbatim environment ?
    – krshk
    Jul 13, 2016 at 18:43
  • @krshk I'm sorry that I have no experience with fancyvrb, other than superficial exposure. Jul 13, 2016 at 23:49

You must log in to answer this question.

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