我目前有一个用例,其中为 PowerPoint 创建了一组图形精美的目录幻灯片,我想复制 LaTeX 投影仪的设计,同时保留自动填充当前内容的功能,这些内容通常会被弹出到而\tableofcontents
不是tikzpicture
正常的列表环境中。我最好在不需要双重编译的情况下执行此操作(通过固定锚点和remember picture,overlay
。
当然原版更有吸引力。;-)
这是显示静态代码(可防止双重编译)的当前版本,它会生成花哨的 ToC,但不会自动生成,还会更改模板section in toc
,这需要双重编译:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{bubble/.style={circle,text width=2cm,align=center,inner sep=2pt}}
\makeatletter
\setbeamertemplate{section in toc}{
\ifnum\the\beamer@tempcount=1
\begin{tikzpicture}[remember picture,overlay]
\fill[green] ($(current page.south west) + (1cm,1cm)$) rectangle ($(current page.north east) - (1cm,1cm)$);
\node(first)[bubble,fill=red] at ($(current page.south west) + (2.4cm,2.5cm)$) {0\inserttocsectionnumber\\ \inserttocsection};
\end{tikzpicture}
\fi
\ifnum\the\beamer@tempcount=2
\begin{tikzpicture}[remember picture,overlay]
\node(second)[bubble,fill=orange] at ($(current page.south west) + (4.5cm,7.2cm)$) {0\inserttocsectionnumber\\ \inserttocsection};
\draw (first) -- (second);
\end{tikzpicture}
\fi
\ifnum\the\beamer@tempcount=3
\begin{tikzpicture}[remember picture,overlay]
\node(third)[bubble,fill=magenta] at ($(current page.south west) + (6cm,3cm)$) {0\inserttocsectionnumber\\ \inserttocsection};
\draw (second) -- (third);
\end{tikzpicture}
\fi
\ifnum\the\beamer@tempcount=4
\begin{tikzpicture}[remember picture,overlay]
\node(fourth)[bubble,fill=pink] at ($(current page.south west) + (8cm,7cm)$) {0\inserttocsectionnumber\\ \inserttocsection};
\draw (third) -- (fourth);
\end{tikzpicture}
\fi
\ifnum\the\beamer@tempcount=5
\begin{tikzpicture}[remember picture,overlay]
\node(fifth)[bubble,fill=cyan] at ($(current page.south west) + (10cm,3cm)$) {0\inserttocsectionnumber\\ \inserttocsection};
\draw (fourth) -- (fifth);
\end{tikzpicture}
\fi
\,%
}
\makeatother
\begin{document}
\begin{frame}
\begin{tikzpicture}
\fill[green] (0,0) rectangle ++(\textwidth,0.85\textheight);
\node(first)[bubble,fill=red] at (0.15\textwidth,0.15\textheight) {01\\First Chapter};
\node(second)[bubble,fill=orange] at (0.3\textwidth,0.7\textheight) {02\\Second Chapter};
\node(third)[bubble,fill=magenta] at (0.45\textwidth,0.3\textheight) {03\\Third Chapter};
\node(fourth)[bubble,fill=pink] at (0.7\textwidth,0.7\textheight) {04\\Fourth Chapter};
\node(fifth)[bubble,fill=cyan] at (0.8\textwidth,0.2\textheight) {05\\Fifth Chapter};
\draw (first) -- (second) -- (third) -- (fourth) -- (fifth);
\end{tikzpicture}
\end{frame}
\frame{\tableofcontents}
\section{First Chapter}
\frame{Test}
\section{Second Chapter}
\frame{Test}
\section{Third Chapter}
\frame{Test}
\section{Fourth Chapter}
\frame{Test}
\section{Fifth Chapter}
\frame{Test}
\end{document}
我尝试了一下修补\tableofcontents
,但我仍然找不到不编译两次的方法,因为这是引用另一个中的节点所必需的tikzpicture
:
\colorlet{bubbleColor}{green}
\tikzset{bubble/.style={circle,fill=bubbleColor,text width=2cm,align=center,inner sep=2pt}}
\usepackage{etoolbox,xfp}
\pretocmd{\tableofcontents}{%
\begin{tikzpicture}[remember picture]
\fill[green] (0,0) rectangle ++(\textwidth,0.85\textheight);
\coordinate(section1) at (0.15\textwidth,0.15\textheight);
\coordinate(section2) at (0.3\textwidth,0.7\textheight);
\coordinate(section3) at (0.45\textwidth,0.3\textheight);
\coordinate(section4) at (0.7\textwidth,0.7\textheight);
\coordinate(section5) at (0.8\textwidth,0.2\textheight);
\end{tikzpicture}}{}{}
\apptocmd{\tableofcontents}{}{}{}
\makeatletter
\setbeamertemplate{section in toc}{
\ifodd\the\beamer@tempcount
\colorlet{bubbleColor}{red}
\else
\colorlet{bubbleColor}{magenta}
\fi
\ifnum\the\beamer@tempcount=1
\begin{tikzpicture}[remember picture,overlay]
\node(section\inserttocsectionnumber)[bubble] at (section\inserttocsectionnumber) {0\inserttocsectionnumber\\ \inserttocsection};
\end{tikzpicture}
\else
\ifnum\the\beamer@tempcount<6
\begin{tikzpicture}[remember picture,overlay]
\node(section\inserttocsectionnumber)[bubble] at (section\inserttocsectionnumber) {0\inserttocsectionnumber\\ \inserttocsection};
\draw (section\inteval{\inserttocsectionnumber - 1}) -- (section\inserttocsectionnumber);
\end{tikzpicture}
\fi
\fi
}
\makeatother
答案1
基于https://topanswers.xyz/tex?q=1987#a2230
第一次运行会出现错误,但你可以添加一些异常处理。第二次运行时,tikz 图片应该会出现
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{mindmap,trees,shadows}
% total number of sections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{totcount}
\newcounter{totalsection}
\regtotcounter{totalsection}
\AtBeginDocument{%
\pretocmd{\section}{\refstepcounter{totalsection}}{}{}%
}%
% number of subsections per section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ExplSyntaxOn % fix xcntperchap
\cs_set_eq:NN \c_zero \c_zero_int
\ExplSyntaxOff
\usepackage{xcntperchap}
\RegisterCounters{section}{subsection}
\newcounter{totalsubsection}
\setcounter{totalsubsection}{0}
% creating automatic label %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% based on https://tex.stackexchange.com/a/386557/36296
\AtBeginSection[]{\label{sec:\thesection}}
\AtBeginSubsection[]{\label{subsec:\thesection:\thesubsection}}
\newcounter{currentsub}
\newcounter{totsection}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzset{bubble/.style={circle,text width=2cm,align=center,inner sep=2pt}}
\newcounter{foo}
\newcommand{\mindtoc}{%
\centering
\setcounter{totsection}{\number\totvalue{totalsection}}
\begin{tikzpicture}
\fill[green] (0,0) rectangle ++(\textwidth,0.85\textheight);
\coordinate(section1) at (0.15\textwidth,0.15\textheight);
\coordinate(section2) at (0.3\textwidth,0.7\textheight);
\coordinate(section3) at (0.45\textwidth,0.3\textheight);
\coordinate(section4) at (0.7\textwidth,0.7\textheight);
\coordinate(section5) at (0.8\textwidth,0.2\textheight);
\foreach \mysec in {1,...,\thetotsection}{%
\setcounter{foo}{\mysec}
\addtocounter{foo}{1}
\ifnum\thetotsection<\thefoo
\else
\draw (section\thefoo) -- (section\mysec);
\fi
\ifodd\mysec
\colorlet{bubbleColor}{red}
\else
\colorlet{bubbleColor}{magenta}
\fi
\node[circle,fill=bubbleColor,text width=2cm,align=center,inner sep=2pt] at (section\mysec) {
\mysec\\
\hyperlink{sec:\mysec}{\nameref{sec:\mysec}}
};
% };
}
\end{tikzpicture}
}
\title{Some Title}
\begin{document}
% \tracingall
\begin{frame}[fragile]
\frametitle{"Table" of Contents}
\mindtoc
\end{frame}
\section{Section One}
\frame{abc}
\section{Section Two}
\frame{abc}
\subsection{subsection a}
\frame{abc}
\subsection{subsection b}
\frame{abc}
\subsection{subsection c}
\frame{abc}
\section{Section Three}
\frame{abc}
\section{Section Four}
\frame{abc}
\end{document}
答案2
现在,我的解决方案是先定义自己的命令,然后读取文件,而不是操纵\tableofcontents
命令或摆弄文件。如下所示:TOC
TOC
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{calc}
\colorlet{bubbleColor}{orange}
\tikzset{bubble/.style={circle,fill=bubbleColor,text width=1.5cm,align=center,inner sep=2pt,font=\small}}
\begin{document}
\makeatletter
\let\beameroriginal@sectionintoc\beamer@sectionintoc
%%%%\def\beamer@endinputifotherversion#1{}
\renewcommand{\beamer@sectionintoc}[5]{ \ifodd#1%
\colorlet{bubbleColor}{red}%
\else%
\colorlet{bubbleColor}{magenta}%
\fi%
\node(bubble#1)[bubble] at (section#1) {#2};}
%%%%\def\beamer@subsectionintoc#1#2#3#4#5#6{}
%%%%\def\beamer@subsubsectionintoc#1#2#3#4#5#6#7{}
\frame{
\begin{tikzpicture}
\fill[green] (0,0) rectangle ++(\textwidth,0.85\textheight);
\coordinate(section1) at (0.15\textwidth,0.15\textheight);
\coordinate(section2) at (0.3\textwidth,0.7\textheight);
\coordinate(section3) at (0.45\textwidth,0.3\textheight);
\coordinate(section4) at (0.7\textwidth,0.7\textheight);
\coordinate(section5) at (0.8\textwidth,0.2\textheight);
\@input{\jobname.toc}
\draw (bubble1) -- (bubble2) -- (bubble3) -- (bubble4) -- (bubble5);
\end{tikzpicture}
}
\let\beamer@sectionintoc\beameroriginal@sectionintoc
\makeatother
\frame{\tableofcontents}
\section{First Chapter}
\frame{Test}
\section{Second Chapter}
\frame{Test}
\section{Third Chapter}
\frame{Test}
\section{Fourth Chapter}
\frame{Test}
\section{Fifth Chapter}
\frame{Test}
\end{document}