2

I am trying to put a box around matlab code but the bottom of the box sits extremely close to the next line. I try a line break but it does not work. Any ideas?

\documentclass[a4paper,12pt]{article}
\usepackage{mdframed}
\begin{document}
...get,\\

\begin{mdframed}
\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}
bla bla bla
Troy
  • 13,741

2 Answers2

5

You can add vertical space above and below an mdframed environment by assigning nonzero (length) values to the skipabove and skipbelow optional keys, respectively. For instance:

\documentclass{book}

\usepackage{mdframed}

\begin{document}

favorite
I am trying to put a box around matlab code but the bottom of the box sits extremely close
to the next line. I try a line break but it does not work. Any ideas?

...get,\\

\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}

gives

enter image description here

David Carlisle
  • 757,742
jub0bs
  • 58,916
3

This is to show an alternative for matlab code with highlighting.

It is better to use mcode to typeset the matlab codes. mcode internally uses listings package and offers features like different colored text etc.

An example:

\documentclass{article}

% load package with ``framed'' and ``numbered'' option.
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\lstset{
    rulecolor=\color{black}
}

% something NOT relevant to the usage of the package.
\setlength{\parindent}{0pt}
\setlength{\parskip}{18pt}

\begin{document}
 The following demo block shows some matlab code:
\begin{lstlisting}
for i = 1:3
    if i >= 5                    % literate programming replacement some thing to fill in the space
        disp('cool');           % comment with some §\mcommentfont\LaTeX\ in it: $\mcommentfont\pi x^2$§
    end
    really really long really really long really really long really really long really really long line % blaaaaaaaa
end
\end{lstlisting}
\end{document}

enter image description here

enter image description here

You can add captions by using

\begin{lstlisting}[caption=My code here]