I'm using the listings
package to include code directly from a file. In the first instance my code is numbered as I want it 1 at the 1st line, 11 at the 11th, ... However, the second block of code it numbers 2 on the 2nd line, 12 on the 12th line, ... then the first numbering 8 on the 8th line.
Any suggestions on how to fix this?
Here is my code:
\documentclass{article}
\usepackage{listings, color, setspace, graphics}
\usepackage{fancyhdr, amsmath, amssymb, setspace, amssymb}
\usepackage{pdfpages}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{ %
language=C++, % the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\tiny\color{gray}, % the style that is used for the line-numbers
stepnumber=10, % the step between two line-numbers. If it's 1, each line
% will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
keywordstyle=\color{blue}, % keyword style
commentstyle=\color{dkgreen}, % comment style
stringstyle=\color{mauve}, % string literal style
}
\renewcommand{\baselinestretch}{1}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.5in}
\setlength{\topmargin}{0in}
\setlength{\oddsidemargin}{0in}
\setlength{\evensidemargin}{0in}
\setlength{\parindent}{.3in}
\pagestyle{fancy}
\sloppy
\definecolor{lightgray}{gray}{0.5}
\setlength{\parindent}{0pt}
\begin{document}
\setcounter{page}{11}
\lhead{John Haase}
\chead{AME 60614 Numerical Methods - Homework 2}
\rhead{\thepage}
\cfoot{}
\section*{Problem 1 Source Code}
\subsection*{C++ Code}
\lstset{language=C++}
\lstinputlisting{Problem1/Problem1.cpp}
\clearpage
\section*{Problem 2 Source Code}
\subsection*{C++ Code}
\lstset{language=C++}
\lstinputlisting{Problem2/Problem2.cpp}
\clearpage
\subsection*{MATLAB Code}
\lstset{language=Matlab}
\lstinputlisting{Problem2/Problem2.cpp}
\clearpage
\end{document}
stepnumber=10, firstnumber=1, numberfirstline=true,
.matlab-prettifier
package; see this answer.