beamer 中代码列表的背景图像

beamer 中代码列表的背景图像

我最初问这个问题是为了尝试获取代码清单后面的背景图像。

代码清单的背景图片

我没有提到的是,我正在使用 beamer 包制作幻灯片。这种技术似乎不适用于 beamer。我在代码列表后面看到一个灰色框。

如何在 beamer 中获取代码列表后面的背景图像?`

\documentclass{beamer}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand*{\AddBackgroundImage}[4][]{%
%\pgfmathsetmacrp{\height}{}%
    \begin{tikzpicture}[overlay,remember picture]
    \coordinate (VCenter) at ($(#2)!0.5!(#3)$);
    \coordinate (Fudge) at (-\pgflinewidth,0);
    \coordinate (VFudge) at (0,\baselineskip);
    %\draw [red, thick,fill=yellow, fill opacity=0.2]% for debugging
    \clip
            ($(#2)+ (Fudge) - 0.50*(VFudge)$) -- 
            ($(#2) + (\linewidth,0) - 0.50*(VFudge)$) -- 
            ($(#3) + (\linewidth,0) + 1.25*(VFudge)$) --
            ($(#3)+ (Fudge) + 1.25*(VFudge)$) -- cycle;
    \path (VCenter) -- ++($(0.5*\linewidth,0)$) 
    node [opacity=0.3, #1] {\includegraphics[width=\linewidth]{#4}};
    \end{tikzpicture}%
}%

\usetheme {default}
\lstset{ language=Haskell 
       , basicstyle=\small\sffamily
       , numbers=left 
       , numberstyle=\tiny\color{gray}  
       }


\begin{document}     
\begin{frame}[fragile]  

\noindent% Line above MUST be blank
\tikzmark{Start}%
\begin{lstlisting}
data PersonRecord = 
  PersonRecord { firstname      :: FirstName,
                 lastname       :: LastName,
                 middleinitial  :: Maybe MiddleInitial,
                 gender         :: Gender,
                 favoritecolor  :: FavoriteColor,
                 dateofbirth    :: CalendarTime 
               } deriving (Show)

\end{lstlisting}
\end{frame}
\tikzmark{End}
\AddBackgroundImage{Start}{End}{images/black-screen}%
%
\noindent
Some text afterwards.
\end{document}

答案1

只需在环境内\tikzmark{End}移动即可解决问题(文档必须处理两次):\AddBackgroundImageframe

\documentclass{beamer}
\usepackage{listings}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing}

\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}

\newcommand*{\AddBackgroundImage}[4][]{%
%\pgfmathsetmacrp{\height}{}%
    \begin{tikzpicture}[overlay,remember picture]
    \coordinate (VCenter) at ($(#2)!0.5!(#3)$);
    \coordinate (Fudge) at (-\pgflinewidth,0);
    \coordinate (VFudge) at (0,\baselineskip);
    %\draw [red, thick,fill=yellow, fill opacity=0.2]% for debugging
    \clip
            ($(#2)+ (Fudge) - 0.50*(VFudge)$) -- 
            ($(#2) + (\linewidth,0) - 0.50*(VFudge)$) -- 
            ($(#3) + (\linewidth,0) + 1.25*(VFudge)$) --
            ($(#3)+ (Fudge) + 1.25*(VFudge)$) -- cycle;
    \path (VCenter) -- ++($(0.5*\linewidth,0)$) 
    node [opacity=0.3, #1] {\includegraphics[width=\linewidth]{#4}};
    \end{tikzpicture}%
}%

\usetheme {default}
\lstset{ language=Haskell 
       , basicstyle=\small\sffamily
       , numbers=left 
       , numberstyle=\tiny\color{gray}  
       }


\begin{document}     

\begin{frame}[fragile]  

\tikzmark{Start}%
\begin{lstlisting}
data PersonRecord = 
  PersonRecord { firstname      :: FirstName,
                 lastname       :: LastName,
                 middleinitial  :: Maybe MiddleInitial,
                 gender         :: Gender,
                 favoritecolor  :: FavoriteColor,
                 dateofbirth    :: CalendarTime 
               } deriving (Show)

\end{lstlisting}
\tikzmark{End}
\AddBackgroundImage{Start}{End}{ctanlion}%

Some text afterwards.
\end{frame}

\end{document}

在此处输入图片描述

CTAN 狮子绘画由 Duane Bibby 绘制。

相关内容