创建 verbatim mdframed 环境

创建 verbatim mdframed 环境

我想mdframed在其中使用环境verbatim。我读过两份文档,也搜索过 Google,但没有找到任何与此有关的信息。

MWE 如下:

\documentclass[10pt]{article}

\usepackage[a4paper,pdftex]{geometry}
\usepackage[headings]{fullpage}

\usepackage[utf8]{inputenc}
\usepackage[magyar]{babel}
\usepackage[T1]{fontenc}

\usepackage{color}
\definecolor{shadecolor}{gray}{0.90}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage{verbatim}

\usepackage[framemethof=tikz,%
innerleftmargin=\parindent,%
linewidth=0pt,%
backgroundcolor=shadecolor,%
skipabove=0.6\baselineskip,%
skipbelow=0.6\baselineskip]{mdframed}


% How to create a new environment that uses mdframed and verbatim?
\newenvironment{magic}
{\begin{mdframed}}
{\end{mdframed}}

\begin{document}

\begin{mdframed} % How to make these
\begin{verbatim} % two into one?
From: [email protected] (Linus Benedict Torvalds)
Newsgroups: comp.os.minix
Subject: What would you like to see most in minix?
Summary: small poll for my new operating system
Keywords: 386, preferences
Message-ID: <[email protected]>
Date: 25 Aug 91 20:57:08 GMT
Organization: University of Helsinki
Lines: 20


Hello everybody out there using minix -

I'm doing a (free) operating system (just a hobby, won't be big and
professional like gnu) for 386(486) AT clones.  This has been brewing
since april, and is starting to get ready.  I'd like any feedback on
things people like/dislike in minix, as my OS resembles it somewhat
(same physical layout of the file-system (due to practical reasons)
among other things). 

I've currently ported bash(1.08) and gcc(1.40), and things seem to work.
This implies that I'll get something practical within a few months, and
I'd like to know what features most people would want.  Any suggestions
are welcome, but I won't promise I'll implement them :-)

        Linus ([email protected])

PS.  Yes - it's free of any minix code, and it has a multi-threaded fs.
It is NOT protable (uses 386 task switching etc), and it probably never
will support anything other than AT-harddisks, as that's all I have :-(.
\end{verbatim} % How to make these
\end{mdframed} % two into one?

\end{document}

附言我不想使用该listings包,因为我可以完美地设置边距和内容mdframed,并且我不需要代码突出显示。

答案1

以下对我来说非常有效:

\documentclass[10pt]{article}

\usepackage[a4paper,pdftex]{geometry}
\usepackage[headings]{fullpage}

\usepackage[utf8]{inputenc}

\usepackage[T1]{fontenc}

\usepackage{color}
\definecolor{shadecolor}{gray}{0.90}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage{verbatim}

\usepackage[framemethod=tikz,%
innerleftmargin=\parindent,%
linewidth=0pt,%
backgroundcolor=gray,%
skipabove=0.6\baselineskip,%
skipbelow=0.6\baselineskip]{mdframed}


% How to create a new environment that uses mdframed and verbatim?
\newenvironment{magic}
{\begin{mdframed}}
{\end{mdframed}}

\begin{document}

\begin{mdframed} % How to make these
\begin{verbatim}

\end{verbatim} % How to make these
\end{mdframed} % two into one?
  <snip>
\end{document}

请注意,我更正了您的拼写错误:framemethofvsframemethod并且我更改了正在使用的颜色。它给我的错误是: 。我怀疑这与和Package pgfbase Error: Unsupported color model '0'. Sorry \end{mdframed}的组合有关。因为当我用一些文本替换环境时,我得到了同样的错误。mdframedverbatimverbatim

编辑:Marco 的评论让我意识到我误解了这个问题。我现在假设您主要关心的是获得一个在 mdframed 内部逐字工作的新的环境。您可以使用 Marco 在评论中建议的构造以及为创建一个新的环境verbatim。以下代码:

\newenvironment{myverb}
{\endgraf\verbatim}
{\endverbatim}

\BeforeBeginEnvironment{myverb}{\begin{mdframed}}
\AfterEndEnvironment{myverb}{\end{mdframed}}

然后您可以在文档中使用它\begin{myverb} ...\end{myverb}来获取环境verbatim的内部信息mdframed

相关内容