5

I want to write shell Code in my LaTeX document. I'm using the listings package, with a code sample adapted from Tormod Fjeldskår:

\documentclass{report}

\usepackage{color}
\usepackage{xcolor}
\usepackage{listings}

\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}

% This concludes the preamble

\begin{document}

\begin{lstlisting}[label=some-code,caption=Some Code]
   NETWORKING=YES

HOSTNAME= f e −19. l o c a l d o m a i n

}
\end{lstlisting}

\end{document}

The problem is that there is some extra space between every character when I generate a PDF. I would like the code without this space. The extra space is visible in the the part HOSTNAME=.

13

columns=fullflexible solved the problem.

By default, the spacing between characters is made uniform so as to preserve alignments. Setting columns to a non-default value restores the inter-character spacing (all characters are typeset at their natural width) but may break alignments.

For example:

\begin{lstlisting}[columns=fullflexible,caption=The Name]
dladm show-phys
\end{lstlisting}

Instead of fullflexible, you can use flexible or space-flexible, which try to preserve alignment by adjusting horizontal whitespace between words. For more information, see the section on the columns option in the listings manual (§2.10 “Fixed and flexible columns”).

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