# Alignment of minted line numbers

I'm using the minted package for code highlighting. The below is just a minimal example. What I find annoying about this package is that line numbers appear in the margin.

This causes several problems with \items but also in twocolumn articles. What I would like is to have the line numbers aligned with the normal text, like so:

I have read through the documentation, but there doesn't seem to be such an option. The numbers=right option doesn't help me either: I don't want numbers on the right, and even if I would, that option places numbers in the right margin.

I have tried putting it altogether in a minipage (i.e. \begin{minipage}{\linewidth}\begin{minted} ... \end{minted}\end{minipage}), but couldn't get spacing work properly.

What would be the preferred way to move the numbers to the right?

\documentclass[10pt]{article}

\usepackage{minted,lipsum}

\begin{document}

\lipsum[1]

\begin{minted}[linenos,breaklines]{text}
Donec vehicula augue eu neque.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Mauris ut leo.
Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices.
\end{minted}

\lipsum[2]

\end{document}


Use xleftmargin:

\documentclass[10pt]{article}

\usepackage{minted,lipsum}

\begin{document}

\lipsum[1]

\begin{minted}[xleftmargin=\parindent,linenos,breaklines]{text}
Donec vehicula augue eu neque.
Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
Mauris ut leo.
Cras viverra metus rhoncus sem.
Nulla et lectus vestibulum urna fringilla ultrices.
\end{minted}

\lipsum[2]

\end{document}


You may also want to modify numbersep; the default is numbersep=12pt.

For instance, if you want that the line numbers (two digits) are flush with the left margin, you can do

\newlength{\mintednumbersep}
\AtBeginDocument{%
\sbox0{\tiny00}%
\setlength\mintednumbersep{\parindent}%

and then set numbersep=\mintednumbersep.
• I searched for number in the documentation, not for margin... Thanks! Jun 25 '15 at 20:39