我正在尝试重现:
我对以下代码取得了一些进展:
\documentclass{beamer}
\usetheme{default}
\usepackage{enumitem}
\usepackage{framed}
\usepackage[framemethod=TikZ]{mdframed}
\title{Beamer Template}
\begin{document}
\begin{frame}
\end{frame}
\begin{mdframed}
\begin{itemize}[label={}]
\item \textsc{Traverse}($s$)
\vspace{0.5cm}
\item put $\color{blue}s$ into the \textcolor{green}{bag}
\item while the \textcolor{green}{bag} is not empty
\begin{itemize}
\item take $\color{blue}u$ from the bag
\item if $\color{blue}u$ unmarked
\item \textcolor{red}{mark} $\color{blue}u$
\item for every edge $\color{blue}(u,v)$
\begin{itemize}
\item put $\color{blue}v$ into the bag
\end{itemize}
\end{itemize}
\end{itemize}
\end{mdframed}
\end{document}
为了完成这个我需要:
- 使框架适合文本
- 使框架更厚
- 找到合适的字体
- 找到正确的颜色
我可以做最后一个。我该怎么做其他三个?
答案1
你可以尝试一些完全不同的东西。
文章(报告或书籍)文档类别
\documentclass{article}
\usepackage{minted}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\tcbset{
arc=0pt,
outer arc=0pt,
colback=white,
}
\definecolor{code-yellow}{RGB}{232, 168, 24}
\definecolor{code-blue}{RGB}{0, 114, 178}
\definecolor{code-green}{RGB}{0, 158, 115}
\begin{document}
\begin{tcolorbox}[text width=5cm]
\begin{minted}[escapeinside=||,mathescape=true]{text}
|\textsc{Traverse}|(|\color{code-blue}{$s$}|)
put |\color{code-blue}{$s$}| into the |\textcolor{code-yellow}{bag}|
while the |\textcolor{code-yellow}{bag}| is not empty
take |$\color{code-blue}u$| from the |\textcolor{code-yellow}{bag}|
if |\color{code-blue}{$u$}| unmarked
|\textcolor{code-green}{mark}| |$\color{code-blue}u$|
for every edge |$\color{code-blue}(u,v)$|
put |$\color{code-blue}v$| into the |\textcolor{code-yellow}{bag}|
\end{minted}
\end{tcolorbox}
\end{document}
投影仪文档类
\documentclass{beamer}
\usepackage{minted}
\usepackage[many]{tcolorbox}
\tcbuselibrary{skins}
\tcbset{
arc=0pt,
outer arc=0pt,
colback=white,
}
\definecolor{code-yellow}{RGB}{232, 168, 24}
\definecolor{code-blue}{RGB}{0, 114, 178}
\definecolor{code-green}{RGB}{0, 158, 115}
\begin{document}
\begin{frame}[fragile]
\begin{tcolorbox}[text width=5.5cm]
\begin{minted}[escapeinside=||,mathescape=true]{text}
|\textsc{Traverse}|(|\color{code-blue}{$s$}|)
put |\color{code-blue}{$s$}| into the |\textcolor{code-yellow}{bag}|
while the |\textcolor{code-yellow}{bag}| is not empty
take |$\color{code-blue}u$| from the |\textcolor{code-yellow}{bag}|
if |\color{code-blue}{$u$}| unmarked
|\textcolor{code-green}{mark}| |$\color{code-blue}u$|
for every edge |$\color{code-blue}(u,v)$|
put |$\color{code-blue}v$| into the |\textcolor{code-yellow}{bag}|
\end{minted}
\end{tcolorbox}
\end{frame}
\end{document}
答案2
您可以使用semiverbatim
内置的beamer
。
\documentclass{beamer}
\usetheme{default}
\usepackage[framemethod=TikZ]{mdframed}
\title{Beamer Template}
\newcommand{\Proc}[1]{\textsc{#1}}
\newcommand{\Var}[1]{\ensuremath{\textcolor{varcolor}{#1}}}
\newcommand{\Tag}[1]{\textcolor{tagcolor}{#1}}
\newcommand{\Com}[1]{\textcolor{comcolor}{#1}}
\definecolor{varcolor}{RGB}{15,122,183}
\definecolor{tagcolor}{RGB}{230,159,3}
\definecolor{comcolor}{RGB}{10,161,119}
\begin{document}
\begin{frame}[fragile]
\begin{mdframed}
\begin{semiverbatim}
\Proc{Traverse}(\Var{s})
put \Var{s} into the \Tag{bag}
while the \Tag{bag} is not empty
take \Var{u} from the bag
if \Var{u} unmarked
\Com{mark} \Var{u}
for every edge \Var{(u,v)}
put \Var{v} into the \Tag{bag}
\end{semiverbatim}
\end{mdframed}
\end{frame}
\end{document}
不要忘记这个fragile
选择。
另一种方法是使用BVerbatim
from fancyvrb
。
\documentclass{beamer}
\usetheme{default}
\usepackage{fancyvrb}
\title{Beamer Template}
\newcommand{\Proc}[1]{\textsc{#1}}
\newcommand{\Var}[1]{\ensuremath{\textcolor{varcolor}{#1}}}
\newcommand{\Tag}[1]{\textcolor{tagcolor}{#1}}
\newcommand{\Com}[1]{\textcolor{comcolor}{#1}}
\definecolor{varcolor}{RGB}{15,122,183}
\definecolor{tagcolor}{RGB}{230,159,3}
\definecolor{comcolor}{RGB}{10,161,119}
\newenvironment{pseudocode}
{%
\VerbatimEnvironment
\begin{lrbox}{\pseudocodebox}
\fvset{commandchars=\\\{\}}
\begin{BVerbatim}
}
{\end{BVerbatim}\end{lrbox}\fbox{\usebox{\pseudocodebox}}}
\newsavebox{\pseudocodebox}
\begin{document}
\begin{frame}[fragile]
\begin{pseudocode}
\Proc{Traverse}(\Var{s})
put \Var{s} into the \Tag{bag}
while the \Tag{bag} is not empty
take \Var{u} from the bag
if \Var{u} unmarked
\Com{mark} \Var{u}
for every edge \Var{(u,v)}
put \Var{v} into the \Tag{bag}
\end{pseudocode}
\end{frame}
\end{document}
据我所知,mdframed
始终使用整个文本宽度。请查看以tcolorbox
了解更强大的方法。