30 如何根据页码循环调用几个背景 background ?

发布于 2024-06-03 09:49:11

在 Beamer 中,定义 background 背景,可选参数是几个颜色 (incolor0-9) 对应几个背景,根据根据页码循环调用这些背景,如何实现

\definecolor{incolor0}{RGB}{176,196,222}
\definecolor{incolor1}{RGB}{255,249,220}
\definecolor{incolor2}{RGB}{249,249,255}
\definecolor{incolor3}{RGB}{240,255,240}
\definecolor{incolor4}{RGB}{211,211,211}
\definecolor{incolor5}{RGB}{176,196,222}
\definecolor{incolor6}{RGB}{175,238,238}
\definecolor{incolor7}{RGB}{253,246,230}
\definecolor{incolor8}{RGB}{255,250,250}
\definecolor{incolor9}{RGB}{154,205,50}

% 定义一个新的背景模板
\defbeamertemplate{background}{overlay}[1][incolor0]{
    \begin{tikzpicture}[remember picture,overlay]
    % 设置纯色背景
    \fill[bgcolor] (current page.south west) rectangle (current page.north east);
    % 计算要绘制圆角矩形的位置
    \coordinate (SW) at ($(current page.south west) + (0.275cm,0.275cm)$);
    \coordinate (NE) at ($(current page.north east) + (-0.275cm,-0.275cm)$);
    % 添加一个圆角矩形
    \filldraw[fill=#1, rounded corners=0.64cm, draw=bdcolor, line width=0.6pt]
    (SW) rectangle (NE);
\end{tikzpicture}
}
% 调用某个颜色的背景是可以的
%\setbeamertemplate{background}[overlay][incolor1]

尝试下面这样根据颜色编号 incolor0-9 循环,是失败的

\mode<beamer>{%
\pgfmathtruncatemacro{\colorindex}{mod(\insertframenumber,10)}
\expandafter\def\csname incolorcurrent\endcsname{incolor\colorindex}
\setbeamertemplate{background}[overlay][\csname incolorcurrent\endcsname]
}

如果这种定义不行,有其他的方式吗?
源文件 background.zip

查看更多

关注者
0
被浏览
188
芒果不盲
芒果不盲 2024-06-03
学好TiKZ和tcolorbox!
% 定义一个新的背景模板
\defbeamertemplate{background}{overlay}{
    \begin{tikzpicture}[remember picture,overlay]
    \pgfmathtruncatemacro{\colorindex}{mod(\insertframenumber,10)}
    % 设置纯色背景
    \fill[bgcolor] (current page.south west) rectangle (current page.north east);
    % 计算要绘制圆角矩形的位置
    \coordinate (SW) at ($(current page.south west) + (0.275cm,0.275cm)$);
    \coordinate (NE) at ($(current page.north east) + (-0.275cm,-0.275cm)$);
    % 添加一个圆角矩形
    \filldraw[fill=incolor\colorindex, rounded corners=0.64cm, draw=bdcolor, line width=0.6pt]
    (SW) rectangle (NE);
\end{tikzpicture}
}

\mode<beamer>{%
\setbeamertemplate{background}[overlay]
}
1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览