mdframed 的问题

mdframed 的问题

我试图在 matlab 代码周围放置一个框,但框的底部非常靠近下一行。我尝试换行,但没有成功。有什么想法吗?

\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

答案1

您可以通过分别为和可选键mdframed分配非零(长度)值来在环境上方和下方添加垂直空间。例如:skipaboveskipbelow

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

给出

在此处输入图片描述

答案2

这是为了展示带有突出显示的 matlab 代码的替代方法。

最好使用代码排版 matlab 代码。mcode内部使用listings包并提供不同颜色的文本等功能。

一个例子:

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

在此处输入图片描述

在此处输入图片描述

您可以使用

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

相关内容