Stack Exchange Network
Stack Exchange network consists of 183 Q&A communities including
Stack Overflow
, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this community
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I will setup my document to the Sans Serif Font
Helvet
and additionally all source codes should display with
Dejavu Sans Mono
and grey background color (on
\lstinline{}
too). How can I setup
listings
correctly to do so?
\documentclass[idxtotoc,hyperref,openany,ngerman,11pt]{article}
\usepackage[a4paper,
inner=30mm, outer=20mm,
top=25mm, bottom=25mm,
headheight=15mm, headsep=7mm
]{geometry}
\usepackage{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\fontfamily{phv}\selectfont
\usepackage{amsmath,amsfonts,amssymb,amsthm,cancel,icomma,nicefrac,mathrsfs,
eurosym,verbatim,environ,ifthen,ifdraft,pdfpages,float,booktabs}
\allowdisplaybreaks[1]
\usepackage{color}
\definecolor{lstgrey}{rgb}{0.95,0.95,0.95}
\usepackage{dejavu}
\usepackage{listings}
\lstset{language=C,
backgroundcolor=\color{lstgrey},
frame=single,
basicstyle=\footnotesize\sf,
captionpos=b,
tabsize=2,
\begin{document}
An example listing shows the \lstinline|main()|:
\begin{lstlisting}[caption=main.c]
int main (void)
return 0;
\end{lstlisting}
\end{document}
Using colorbox and a new command I get the inline listing with a background:
\newcommand\code[1]{\colorbox{lstgrey}{{\lstinline`#1`}}}
An example listing shows the \code{main()}:
\documentclass[hyperref,ngerman,11pt]{article}
\usepackage[a4paper,
inner=30mm, outer=20mm,
top=25mm, bottom=25mm,
headheight=15mm, headsep=7mm
]{geometry}
\usepackage{babel}
\usepackage{dejavu}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{amsmath,amsfonts,amssymb,amsthm,cancel,icomma,
nicefrac,mathrsfs,eurosym,verbatim,environ,
ifthen,ifdraft,pdfpages,float,booktabs}
\allowdisplaybreaks[1]
\usepackage{color}
\definecolor{lstgrey}{rgb}{0.95,0.95,0.95}
\usepackage{listings}
\lstset{language=C,
backgroundcolor=\color{lstgrey},
frame=single,
basicstyle=\footnotesize\ttfamily,
captionpos=b,
tabsize=2,
\newcommand\code[1]{\colorbox{lstgrey}{{\lstinline`#1`}}}
\begin{document}
An example listing shows the \code{main()}:
\begin{lstlisting}[caption=main.c]
int main (void)
return 0;
\end{lstlisting}
\end{document}
Helvetica for main body and Dejavu Sans Mono for listings, right? OK, observe this line basicstyle=\footnotesize\ttfamily, with that \ttfamily at the end. In your post you used the \sf which was the reason for not getting the Dejavu Sans Mono but still getting Dejavu Sans for every thing. You also issued the command \renewcommand{\familydefault}{\sfdefault} which confirmed this.
\documentclass[hyperref,ngerman,11pt]{article}
\usepackage[a4paper,
inner=30mm, outer=20mm,
top=25mm, bottom=25mm,
headheight=15mm, headsep=7mm
]{geometry}
\usepackage{babel}
\usepackage{dejavu}
\usepackage[T1]{fontenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{amsmath,amsfonts,amssymb,amsthm,cancel,icomma,nicefrac,mathrsfs,
eurosym,verbatim,environ,ifthen,ifdraft,pdfpages,float,booktabs}
\allowdisplaybreaks[1]
\usepackage{color}
\definecolor{lstgrey}{rgb}{0.95,0.95,0.95}
\usepackage{listings}
\lstset{language=C,
backgroundcolor=\color{lstgrey},
frame=single,
basicstyle=\footnotesize\ttfamily,
captionpos=b,
tabsize=2,
\begin{document}
An example listing shows the \lstinline|main()|:
\begin{lstlisting}[caption=main.c]
int main (void)
return 0;
\end{lstlisting}
\end{document}
–
–
–