Reputation: 31
I'd like to include line-numbers into my code block using Latex. However, currently the line-numbers are outside the grey code block and I don't know how I can adjust this. These are the following settings I have made.
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\small\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
frame=lines,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
The current result looks as followed.
As you can see, the line-numbers 1-8 are outside the grey box. I'd like to have the numbers inside the grey box.
Also, how can I change the font size of the code in the grey box? I'd like to have the fontsize bigger.
Thank you very much in advance!
Upvotes: 0
Views: 1152
Reputation: 203
You can extend the frame around the numbers using the framexleftmargin
option. Adding framexleftmargin=5mm
to the style you provided in your question should do the trick.
This is described on page 38 of the listings package document, and an example on the bottom of that page shows a listing that uses this option to include the line numbers within the box. The listing package documentation is here: https://texdoc.org/serve/listings.pdf/0.
Also, the font size is set by basicstyle=\ttfamily\footnotesize
which is currently setting the font of the code to footnotesize, which is pretty small. You can change this to "normalsize" by simply removing that part of the instruction and leaving basicstyle=\ttfamily
. You can increase the font size further by using \large
, \Large
, or even \huge
.
Upvotes: 2