I am Google-ing now for a while but couldn't find the answer. So here are the questions again:
I am trying to include parts of my C++ source code into a LaTeX document, and right now I am using \lstinputlisting[language=C++, firstline=37, lastline=40]
for this purpose, which seems pretty good for it. The only thing that annoys me is, that it seems impossible to
a) change the font type of the source code in the text. (It looks like 1997 not like 2018 :/ )
b) widen the space between the text and the frame (background-colour)
Right now my example is like this:
\usepackage{listings}
\lstset{ %
backgroundcolor=\color{gray},
basicstyle=\rmfamily,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{mygreen},
extendedchars=true,
frame=single,
keepspaces=true,
keywordstyle=\color{blue},
language=c++,
numbers=none,
numbersep=5pt,
numberstyle=\tiny\color{blue},
rulecolor=\color{mygray},
showspaces=false,
showtabs=false,
stepnumber=5,
stringstyle=\color{mymauve},
tabsize=3,
title=\lstname
}
\begin{document}
\lstinputlisting[language=C++, firstline=37, lastline=300]{../source/document.cc}
/end{document}
And I want to make it look more like, for example, Github now (here is a random Github page, representing how I want the code to look like: https://github.com/tesseract-ocr/tesseract/wiki/APIExample )
Best Answer
I suggest
basicstyle=\ttfamily
(there are several monospaced fonts available) and alsocolumns=fullflexible
.Here I guessed your colors and changed the background color to a much lighter gray.
Using
lstlisting
or\lstinput
is equivalent as far as the output is concerned.An alternative is
minted
.If you want a 21st century monospaced font, here's the result with
minted
after adding(or you could scale the font at the outset, with the specific option).