[Tex/LaTex] Match font between \texttt and text inside lstlisting

fontslistings

I am trying to match the font between the line that says:
reg [8:0] data_saved [0:3]; // memory declaration

and the rest of the lines that are inside lstlisting.
Here is what I get:

enter image description here

My code looks like this:

\documentclass [11pt] {article}
\usepackage{epsfig}
\usepackage{enumitem}
\usepackage{url}
\usepackage{epstopdf}
\usepackage{listings}
\input std-defs
\input EECE2323-header
\begin{document}
\noindent
\lab{3}{LAB3 - Arithmetic and Logic Unit Part II and Register File}

    \texttt{reg [8:0] data\_saved [0:3]; // memory declaration }

and then initialize its values with the \texttt{initial} declaration:


\begin{lstlisting}[xleftmargin=10em]
// Initialize Inputs Stimulus
initial
  begin
     data_saved[0] = 9'b000000001;
     data_saved[1] = 9'b000000010;
     data_saved[2] = 9'b000000011;
     data_saved[3] = 9'b000000100;
     end
\end{lstlisting}


\textbf{Use alu\_reg\_file\_tb.v as your Testbench template.}

\end{document}

But if I try to add \texttt to the lstlisting than I just see the word \texttt in the text.

Any ideas?
Thanks!

Best Answer

You should have a \lstset instruction in your preamble:

\documentclass [11pt] {article}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{url}
\usepackage{epstopdf}
\usepackage{listings}
%\input std-defs
%\input EECE2323-header

\lstset{
  basicstyle=\ttfamily,
  columns=fullflexible,
}

\begin{document}

%\noindent
%\lab{3}{LAB3 - Arithmetic and Logic Unit Part II and Register File}

    \texttt{reg [8:0] data\_saved [0:3]; // memory declaration }

and then initialize its values with the \texttt{initial} declaration:


\begin{lstlisting}[xleftmargin=10em]
// Initialize Inputs Stimulus
initial
  begin
     data_saved[0] = 9'b000000001;
     data_saved[1] = 9'b000000010;
     data_saved[2] = 9'b000000011;
     data_saved[3] = 9'b000000100;
     end
\end{lstlisting}


\textbf{Use alu\_reg\_file\_tb.v as your Testbench template.}

\end{document}

I have commented out the parts that I can't use (the two \input instructions and the line with the \lab macro), but for the rest I didn't touch the file, apart from changing the call to epsfig into the call to graphicx. The former package is obsolete and should not be used in new documents.

enter image description here

Related Question