8

How to change the verbatim text so that a zero shows up with a slash across it? I would like to know if the verbatim text can be changed to say Consolas?

Here is my code:

\documentclass{article}
\usepackage{verbatim}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}
\begin{document}
I wanted to make the table appear like a ``programming" type text:
\begin{verbatim}
-----------------
10  1   0.3 2
20  2   0.9 5
30  3   3   8
40  4   6   9
50  5   8   10
-----------------
\end{verbatim}

%\lstinputlisting{table.txt}

\end{document}
  • \usepackage{inconsolata} but this will change the \ttfamily completely – user31729 Oct 5 '15 at 17:59
  • @ChristianHupfer Hmmm. I see that you already wrote the inconsolata option in your comment, I added it to my answer after OP required a pdflatex option (initially I provided a xelatex approach). Do you want to provide the inconsolata answer? I can edit mine to suppress this part. – Gonzalo Medina Oct 5 '15 at 18:09
  • @GonzaloMedina: No, it's alright. inconsolata will change the complete document font of \ttfamily, which is not wanted (perhaps?). I've not found out the real fontname for \fontfamily so far. (\fontfamily{zi4r}\selectfont` doesn't work in basicstyle, so your answer is an answer – user31729 Oct 5 '15 at 18:12
  • @ChristianHupfer \fontfamily{zi4}\selectfont seems to work (and returning to cmtt as \ttdefault, if desired). – Gonzalo Medina Oct 5 '15 at 18:16
  • @GonzaloMedina: Strange, I got the usual cmtt in the listing – user31729 Oct 5 '15 at 18:18
10

For xelatex:

\documentclass{article}
\usepackage{listings}
\usepackage{fontspec}
\setmonofont{Consolas}

\lstset{
  basicstyle=\ttfamily,
}

\begin{document}

\begin{lstlisting}
10   1    0.3  2
20   2    0.9  5
30   3    3    8
40   4    6    9
50   5    8    10
\end{lstlisting}

\end{document}

enter image description here

Or

\newfontfamily{\ttconsolas}{Consolas}

\lstset{
  basicstyle=\ttconsolas,
}

if you just want to change the mono font for the listings.

For pdflatex, load the inconsolata package:

\documentclass{article}
\usepackage{listings}
\usepackage{inconsolata}


\lstset{
  basicstyle=\ttfamily,
}

\begin{document}

\begin{lstlisting}
10   1    0.3  2
20   2    0.9  5
30   3    3    8
40   4    6    9
50   5    8    10
\end{lstlisting}

\end{document}

Or,

\documentclass{article}
\usepackage{listings}
\usepackage{inconsolata}

\lstset{
  basicstyle=\fontfamily{zi4}\selectfont,
}
\renewcommand*{\ttdefault}{cmtt}

\begin{document}

\begin{lstlisting}
10   1    0.3  2
20   2    0.9  5
30   3    3    8
40   4    6    9
50   5    8    10
\end{lstlisting}

\end{document}

just for listings and the default monospaced font for the rest of the document.

  • Is there also an alternative for pdflatex? – Joe Oct 5 '15 at 18:02
  • @Joe Yes, there is. See my updated answer. – Gonzalo Medina Oct 5 '15 at 18:15

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.