我正在尝试使用listings
。我的 MWE 如下所示,但无法使其工作。任何帮助都将不胜感激。tcolorbox
谢谢beamer
documentclass
平均能量损失
\documentclass{article}
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings}%
\usepackage{xcolor}
\lstset{ % General setup for the package
language={[LaTeX]TeX},
basicstyle=\small\sffamily,
numbers=left,
numberstyle=\tiny,
frame=tb,
tabsize=4,
columns=fixed,
showstringspaces=false,
showtabs=false,
keepspaces,
commentstyle=\color{red},
keywordstyle=\color{blue}
}%
\tcbset{listing engine={listings}}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\section{First Section}
\blindtext
% Redefine the document environment within a group
\begingroup
\renewenvironment{document}{}{}
\renewcommand\documentclass[2][]{}
\begin{tcblisting}{colback=red!5!white,colframe=red!25,left=6mm,
listing options={style=tcblatex,numbers=left,numberstyle=\tiny\color{red!75!black}}}
\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{First Frame}
\blindtext
\end{frame}
\begin{frame}
\frametitle{Second Frame}
\blindtext
\end{frame}
\end{document}
\end{tcblisting}
\end{document}
答案1
我会将 beamer 示例放入一个单独的文件中,该文件可以自行编译。然后,源代码和 beamer 幻灯片可以包含在目标文档中。
在这里,我使用了example01.tex
beamer 文件:
% example01.tex
\documentclass{beamer}
\usepackage{blindtext}
\begin{document}
\begin{frame}
\frametitle{First Frame}
\blindtext
\end{frame}
\begin{frame}
\frametitle{Second Frame}
\blindtext
\end{frame}
\end{document}
编译完此文件后,将结果包含进去\tcbinputlisting
。两个幻灯片在comment
选项中加载:
\documentclass{article}
\usepackage{listings}
\usepackage{tcolorbox}
\tcbuselibrary{listings}%
\usepackage{xcolor}
\lstset{ % General setup for the package
language={[LaTeX]TeX},
basicstyle=\small\sffamily,
numbers=left,
numberstyle=\tiny,
frame=tb,
tabsize=4,
columns=fixed,
showstringspaces=false,
showtabs=false,
keepspaces,
commentstyle=\color{red},
keywordstyle=\color{blue}
}%
\tcbset{listing engine={listings}}
\usepackage[english]{babel}
\usepackage{blindtext}
\begin{document}
\section{First Section}
\blindtext
\tcbinputlisting{listing file=example01.tex,
listing and comment,
comment={\includegraphics[width=\the\dimexpr 0.5\linewidth-1mm\relax,page=1]{example01}\hfill%
\includegraphics[width=\the\dimexpr 0.5\linewidth-1mm\relax,page=2]{example01}},
colback=red!5!white,colframe=red!25,left=6mm,
leftlower=0pt,rightlower=0pt,
listing options={style=tcblatex,numbers=left,numberstyle=\tiny\color{red!75!black}}}
\end{document}
得出: