TransWikia.com

Box around the code?

TeX - LaTeX Asked by MementoMori on May 15, 2021

I have a piece of code written as:

begin{lstlisting}
  code
end{lstlisting}

I want to put a box, around the code.

I have already read this question Source code listing with frame around code?

But I only want a simple box, not the title at the beginning

One Answer

The solution is around page 17 of the manual.

documentclass{article}
usepackage[T1]{fontenc}
usepackage[utf8]{inputenc}
usepackage{listings}
begin{document}
    begin{lstlisting}[frame=single]
    This is my
    code
    end{lstlisting}
end{document}

Produces:

enter image description here

In the manual you have a lot of possible options for the frame, and some warning on how to tweak things if the frames are "wrong" --- it is a good idea to read it!

Correct answer by Rmano on May 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP