10

I want to underline some code in my source code included using listings. I did the following but the underline is including the white space before the statement. How could I do it so that it only underlines "return 0"?

\lstset{
language=C, 
basicstyle=\ttfamily,
moredelim=[is][\underbar]{_}{_},
}

\begin{lstlisting}
int main() {
  _return 0_;
}
\end{lstlisting}
11

Use keepspaces=true as part of your listing settings.

enter image description here

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\begin{document}

\lstset{
  language=C, 
  basicstyle=\ttfamily,
  moredelim=[is][\underbar]{_}{_}
}

\begin{lstlisting}
int main() {
  _return 0_;
}
\end{lstlisting}

\begin{lstlisting}[keepspaces=true]
int main() {
  _return 0_;
}
\end{lstlisting}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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