# Program listing outputs text wider than usual

\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}

-
 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

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.

-