Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This question already has an answer here:

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=.

share|improve this question
    
Related: tex.stackexchange.com/questions/21432/… –  egreg Feb 22 '13 at 13:34
add comment

migrated from stackoverflow.com Feb 22 '13 at 13:29

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Jubobs, Sean Allred, Andrew Swann, Charles Stewart, Svend Tveskæg Apr 11 at 18:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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”).

share|improve this answer
add comment

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