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()}:
Final code with thanks to AboAmmar:
\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}