1

enter image description here

I currently have my pdf looking like this but I want lines 30 and 31 to be green as well. I was wondering if someone knows of a way I can do this?

Here is my Latex

    \begin{enumerate}
    \item [\textbf{Example 1:}]
    \begin{lstlisting}[firstnumber=1]
    int digitOfPi(int n){
        /*
         * Code not shown
    \end{lstlisting}
    ~~$\vdots$\\
    \begin{lstlisting}[firstnumber=30]
         */
         }
    \end{lstlisting}
  • 1
    Welcome! Please complete your example so it can be compiled. That will be much more useful than a mere fragment. – cfr Aug 4 '17 at 3:05
1

The following example provides a workaround for this case. It adds a line comment starting with * to format the ending comment marker as comment. The closing curly brace is left untouched, because it does not belong to the comment.

\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\colorlet{darkgreen}{green!70!black}
\lstset{
  basicstyle=\ttfamily,
  commentstyle=\color{darkgreen},
  identifierstyle=\color{blue},
  numbers=left,
}

\begin{document}
  \begin{enumerate}
    \item [\textbf{Example 1:}] \mbox{}\\
\begin{lstlisting}[language=C, firstnumber=1]
int digitOfPi(int n) {
    /*
     * Code not shown
\end{lstlisting}
\vspace{-3ex}
\begin{lstlisting}[mathescape, numbers=none]
     $\vdots$
\end{lstlisting}
\vspace{-2ex}
\begin{lstlisting}[language=C, firstnumber=30, morecomment={[l]{*}}]
     */
}
\end{lstlisting}
  \end{enumerate}
\end{document}

Result

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.