3

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

MementoMori
  • 317
  • 3
  • 10
  • 5
    Read the manual at page 17: add [frame=single] option. (The manual is available using texdoc listings or here: https://ctan.org/pkg/listings?lang=en) – Rmano Mar 16 '21 at 10:50
  • @Rmano I haven't found any clearly related question except https://tex.stackexchange.com/q/70145/82917 which is however closed as off-topic. I'd say go on and write an answer. – campa Mar 16 '21 at 12:49
  • @campa done. MementoMori: in my answer you have a complete minimal working example (MWE) --- please use a similar thing when posting your next question(s)! – Rmano Mar 16 '21 at 14:04

1 Answers1

6

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!

Rmano
  • 40,848
  • 3
  • 64
  • 125