1

In the following minimal working example, the text of the listing is aligned with the surrounding text, thus the border on the left protrudes into the margin. I prefer to have the frame align with the surrounding text and do not mind the code to be indented as a result.

\documentclass{article}
\usepackage{listings}
\lstset{frame=l}
\begin{document}
\noindent
test
\begin{lstlisting}
code
\end{lstlisting}
More text
\end{document}

I would provide an attempt which you guys can fix, but I have no clue how to tackle this problem. Any help would be greatly appreciated.

1 Answer 1

1

You can increase the left margin (option xleftmargin) by the values of options framesep + framerule. The default of these options can be found in the manual, “4.3.10 Frames”.

\documentclass{article}
\usepackage{listings}
\lstset{frame=l,xleftmargin=3.4pt}
\begin{document}
\noindent
test
\begin{lstlisting}
code
\end{lstlisting}
More text
\end{document}

enter image description here

If you also use a right frame rule, there you can use option xrightmargin analogous.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .