Beamer制作演示文档-5:设置目录页样式

现在,通过代码\begin{frame}{主要内容} \transfade%淡入淡出 \tableofcontents \end{frame}生成的目录页是下面这样的形式
enter description here

经验丰富的老专家说,你这怎么只有文字?这不行,你得加文本框,加阴影,你得有效果!
那就试试吧。使用了如下的代码

\RequirePackage{tikz}%用tikz包来画背景和阴影
\usetikzlibrary{calc}%,shapes.geometric,shapes.callouts}%需要用到的tikz库,calc用于坐标的计算
\newlength{\boxw}%盒子的宽度
\newlength{\boxh}%盒子的高度
\newlength{\boxroundness}%盒子的圆角大小
\newlength{\boxshadowsize}%阴影到盒子之间的距离
\newlength{\tmpa}%临时长度
\setlength{\boxshadowsize}{6pt}%设置阴影到盒子之间的距离
\setlength{\boxroundness}{3pt}%设置盒子的圆角大小

\newsavebox{\shadowblockbox}%新建一个盒子环境
\newenvironment{shadowblock}[1]%这个是自定义的一个阴影盒子,在这里用来放目录的内容。当然,在其它的地方就可以用来放其它的东西。这个盒子会接收一个参数来指定盒子的宽度
	{%
		\begin{lrbox}{\shadowblockbox}%%
			\begin{minipage}{#1}%%
	}%
	{%
		\end{minipage}%
		\end{lrbox}%
		\settowidth{\boxw}{\usebox{\shadowblockbox}}%
		\settodepth{\tmpa}{\usebox{\shadowblockbox}}%
		\settoheight{\boxh}{\usebox{\shadowblockbox}}%
		\addtolength{\boxh}{\tmpa}%
		\addtolength{\boxh}{2\boxroundness}%
		\addtolength{\boxw}{2\boxroundness}%
		\setlength{\boxw}{1.2\boxw}%
		\setlength{\boxh}{1.2\boxh}%
		\setlength{\tmpa}{1.2\tmpa}%
		\begin{tikzpicture}%画背景
			\usebeamercolor{section number projected}
			\foreach \x in {0,.05,...,1}%画阴影,每次改变画的范围,从而实现浓淡的渐变
			{%
				\fill[xshift=\boxshadowsize -1pt,yshift=-\boxshadowsize + 1pt,black,opacity=.04,rounded corners=\boxroundness](\x*\boxshadowsize,\x*\boxshadowsize) rectangle (\boxw -\x*\boxshadowsize,\boxh-\x*\boxshadowsize);
			};%
			\filldraw[inner color=fg,outer color=Grey0,draw=black!50,rounded corners=\boxroundness](0,0) rectangle (\boxw,\boxh);%画出位于阴影前面的盒子
			\node[xshift=3\boxroundness ,yshift=2\boxroundness,inner sep=0pt,outer sep=0pt,anchor=south west](contents) at (0,0) {\usebox{\shadowblockbox}};%放上目录的内容
			\CTEXnumber{\cna}{\inserttocsectionnumber}%把目录编号改为中文形式
			\node[circle,inner color=fg,outer color=Grey0,minimum size=\boxh,inner sep=0pt,anchor=center,left of= contents,node distance = 0.7\boxw] {\cna};%放上目录的编号
		\end{tikzpicture}
	}%


\defbeamertemplate{section in toc}{NGEGTOC}{
	

	\begin{center}
		\begin{shadowblock}{4cm}%
			\inserttocsection%
		\end{shadowblock}%
	\end{center}
}
\setbeamertemplate{section in toc}[NGEGTOC]

出现的是下面的效果
enter description here

posted @ 2020-09-03 11:49  南宫二狗  阅读(3221)  评论(0编辑  收藏  举报