I have several pieces of Matlab script I have put into boxes using the below method. I want to be able to call them listings 1 2 3 4 etc. Preferably a command that will do it automatically for me. New to LaTeX so no idea I have searched and found very little.
\documentclass[a4paper,12pt]{article}
\usepackage{mdframed}
\begin{document}
\begin{mdframed}[skipabove=\topsep,skipbelow=\topsep]
\begin{verbatim}
S = 55; % Value of the underlying
...
V =
2.2147 %This is the value of our put option
\end{verbatim}
\end{mdframed}
\end{document}
Best Answer
If you want to keep your current settings (
mdframed
+verbatim
), you can use the\captionof
command from thecaption
package to obtain a caption. Another option is to use the features provided by thelistings
package (instead of usingmdframed
+verbatim
) to write your listings; thelstlisting
environment gives you the possibility to have a frame and caption for your listings:If you want this to apply automatically, you can surround
verbatim
with amdframed
and use thesettings
key to automatically generate the caption: