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.
\documentclass[12pt]{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}

\texttt{int main(void)} is rendered tighter than in the listing.
What lstlisting option would need changing?

\begin{lstlisting}[numbers=left,language=c,showtabs=true]
int main(void)
{
 printf("Hi world\n");
}
\end{lstlisting}
\end{document}
share|improve this question
    
I think you want to use \lstinline!int main(void)! instead of \texttt. Have a look at the listings manual. It talks about fixed width text. –  TH. Jan 10 '11 at 0:35
    
@TH I think he wants the listing code to be narrower, actually. But the defaults for inline vs. listings are different anyway. (See my answer.) –  Alan Munn Jan 10 '11 at 0:43

1 Answer 1

up vote 1 down vote accepted

This is controlled by the columns specification (see section 2.10 of the listings manual.) You don't say whether you want the spacing to be wider inline (like the code) or narrower in the listing itself.

To make the inline code match your example listing, use:

\lstinline[language=c,columns=fixed]{int main(void)}

To make the listing match the inline code, use:

\begin{lstlisting}[numbers=left,language=c,showtabs=true,columns=flexible]

If you want both to be the same, use the same column specification for both. The default for inline listing is flexible; the default for listings is fixed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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