出于风格原因(我将所有内容都放在块中),我希望将目录也放在块中,但无需为所有部分手动排版。
令我惊讶的是,标准tikz
TOC 在插入块时会产生垃圾。
因此,我尝试了几种方法来构建我想要的行为的近似值(基本上像itemize/enumerate
),但是虽然我设法为破解了一些相当相似的东西sections
,但我无法正确获得子部分。
首先,我以为这只能归结为确切地知道要使用哪些跳过以及如何获得它们(我花了很长时间才弄清楚\global
;感谢https://tex.stackexchange.com/a/43005/42225和https://tex.stackexchange.com/a/119738/42225),但现在我发现了其他奇怪的行为(对于定义完全相同的东西,缩进会发生变化;无法更改字体大小或颜色subsection
等),这就是为什么我向你求助,亲爱的 TeX.SX。
下面的 MWE 是我想使用标准 TOC 功能实现的“参考解决方案”。理想情况下,它们应该完全匹配,但pt
这里或那里的几个 ' 不会对任何人造成伤害。;-)
\documentclass[10pt]{beamer}
\usepackage[english]{babel}
\usepackage{enumerate}
\usepackage{xparse}
\usetheme{Darmstadt}
\NewDocumentCommand{\mytoc}{O{}}{
\begin{frame}{Test}
\begin{block}{Table of Contents}
\vskip 6pt % shouldn't be hardcoded...
\tableofcontents[#1]
\end{block}
\end{frame}
}
%\AtBeginSection{%
% \mytoc[currentsection]
%}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{frame}{Reference}
\begin{block}{Table of Contents}
\begin{enumerate}[1.]
\item Motivation
\item Construction
\item The Method
\item Improvements
\item Applications
\begin{enumerate}[\theenumi.1.]
\item One
\item Two
\item Three
\end{enumerate}
\end{enumerate}
\end{block}
\end{frame}
\begin{frame}{Na\"ive version}
\begin{block}{Doesn't work}
\tableofcontents
\end{block}
\end{frame}
\setbeamertemplate{section in toc}{\item[\inserttocsectionnumber.]\inserttocsection}
\begin{frame}{Trying to use itemize}
\begin{block}{Doesn't work}
\begin{itemize}
\tableofcontents
\end{itemize}
\end{block}
\end{frame}
\newlength{\itemsepEnumi}
\newlength{\labelsepEnumi}
\newlength{\parsepEnumi}
\newlength{\topsepEnumi}
\newlength{\partopsepEnumi}
\newlength{\leftmarginEnumi}
\newlength{\itemsepEnumii}
\newlength{\labelsepEnumii}
\newlength{\parsepEnumii}
\newlength{\topsepEnumii}
\newlength{\partopsepEnumii}
\newlength{\leftmarginEnumii}
\newlength{\partopsepEnumz} % z=zero
\begin{frame}{Data Collection}
\begin{block}{Relevant Values} % see tex.stackexchange.com/a/94949/42225
\begin{enumerate}[1.]
\item \texttt{itemsep}: \the\itemsep \global\itemsepEnumi =\itemsep
\global\labelsepEnumi =\labelsep
\item \texttt{parsep}: \the\parsep \global\parsepEnumi =\parsep
\item \texttt{topsep}: \the\topsep \global\topsepEnumi =\topsep
\item \texttt{partopsep}: \the\partopsep \global\partopsepEnumi =\partopsep
\item \texttt{leftmargin}: \the\leftmargin \global\leftmarginEnumi=\leftmargin
\begin{enumerate}[\theenumi.1.]
\item \texttt{itemsep}: \the\itemsep \global\itemsepEnumii =\itemsep
\global\labelsepEnumii =\labelsep
\global\parsepEnumii =\parsep
\global\topsepEnumii =\topsep
\item \texttt{partopsep}: \the\partopsep \global\partopsepEnumii =\partopsep
\item \texttt{leftmargin}: \the\leftmargin \global\leftmarginEnumii=\leftmargin
\end{enumerate}
\end{enumerate}
\global\partopsepEnumz=\partopsep
\end{block}
\end{frame}
\begin{frame}{Data Collection -- Successful}
\begin{block}{Relevant Values}
\begin{enumerate}[1.]
\item \texttt{itemsep}: \the\itemsepEnumi
% \item \texttt{labelsep}: \the\labelsepEnumi
\item \texttt{parsep}: \the\parsepEnumi
\item \texttt{topsep}: \the\topsepEnumi
\item \texttt{partopsep}: \the\partopsepEnumi
\item \texttt{leftmargin}: \the\leftmarginEnumi
\begin{enumerate}[\theenumi.1.]
\item \texttt{itemsep}: \the\itemsepEnumii
% \item \texttt{labelsep}: \the\labelsepEnumii
% \item \texttt{parsep}: \the\parsepEnumii
% \item \texttt{topsep}: \the\topsepEnumii
\item \texttt{partopsep}: \the\partopsepEnumii
\item \texttt{leftmargin}: \the\leftmarginEnumii
\end{enumerate}
\end{enumerate}
%\texttt{partopsep}: \the\partopsepEnumz
\end{block}
\end{frame}
\setlength{\leftmarginEnumii}{33.3334pt} % how to add skips?
\setbeamertemplate{section in toc}{\leavevmode\leftskip=\leftmarginEnumi%
\llap{\inserttocsectionnumber.\hspace{\labelsepEnumi}} % why is this automatically blue?
{\color{black}\smash[b]{\inserttocsection}}\par\vskip\itemsepEnumi}
\setbeamertemplate{section in toc shaded}{\leavevmode\leftskip=\leftmarginEnumi%
{\color{gray}\llap{\inserttocsectionnumber.\hspace{\labelsepEnumi}}\smash[b]{\inserttocsection}} \par\vskip\itemsepEnumi\vskip\parsepEnumi}
\setbeamertemplate{subsection in toc}{\leavevmode\leftskip=\leftmarginEnumii%
\llap{%\usetemplate{itemize 2 item} % can't set color/fontsize?!
\inserttocsectionnumber.\inserttocsubsectionnumber.\hspace{\labelsepEnumii}}
{\color{black}\smash[b]{\inserttocsubsection}} \par\vskip\itemsepEnumii \vskip\parsepEnumii}
\setbeamertemplate{subsection in toc shaded}{\leavevmode\leftskip=\leftmarginEnumii%
{\color{gray}\llap{\inserttocsectionnumber.\inserttocsubsectionnumber.\hspace{\labelsepEnumii}}\smash[b]{\inserttocsubsection}} \par\vskip\itemsepEnumii\vskip\parsepEnumii}
\begin{frame}{Trying to Use Skips}
\begin{block}{Doesn't work}
\vskip\partopsepEnumz % is this the right set/combination of skips?
\vskip\partopsepEnumi
\vskip\topsepEnumi
\tableofcontents
\end{block}
\end{frame}
\begin{frame}{Reference}
\begin{block}{Table of Contents}
\begin{enumerate}[1.]
\item Motivation
\item Construction
\item The Method
\item Improvements
\item Applications
\begin{enumerate}[\theenumi.1.]
\item One
\item Two
\item Three
\end{enumerate}
\end{enumerate}
\end{block}
\end{frame}
\begin{frame}{Indentation changes from \texttt{section} to \texttt{section shaded}?!}
\begin{block}{Table of Contents}
\vskip 6pt
\tableofcontents
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Motivation}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Construction}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{The Method}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Improvements}
\mytoc[currentsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Applications}
\subsection{One}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Two}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Three}
\mytoc[currentsection,currentsubsection]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\end{document}
答案1
这并非完美匹配,但或许已经足够接近,至少可以为您提供进一步调整的基础。基本上,这会将环境插入block
到beamer
的定义中,并为\tableofcontents
定义一种新样式。由于它不使用,因此间距并不完全相同,但您可以尝试一下。此外,我已强制颜色与枚举相匹配 - 我不确定您是否想要这样做,但您可以轻松撤消它。my toc
sections/subsections in toc
enumerate
\documentclass[10pt]{beamer}
\usetheme{Darmstadt}
\makeatletter
\def\tableofcontents{\@ifnextchar[{\beamer@tableofcontents}{\beamer@tableofcontents[]}}
\def\beamer@tableofcontents[#1]{%
\begin{block}{\contentsname}
\def\beamer@toc@cs{show}%
\def\beamer@toc@os{show}%
\def\beamer@toc@css{show}%
\def\beamer@toc@oss{show}%
\def\beamer@toc@ooss{show}%
\def\beamer@toc@csss{show}%
\def\beamer@toc@osss{show}%
\def\beamer@toc@oosss{show}%
\def\beamer@toc@ooosss{show}%
\beamer@showpartnumber=\c@part%
\beamer@pausesectionsfalse%
\beamer@pausesubsectionsfalse%
\def\beamer@tocsections{<*>}%
\setkeys{beamertoc}{firstsection=1}%
\setkeys{beamertoc}{#1}%
{\makeatletter%
\pause[0]%
\@input{\jobname.toc}}%
\end{block}
}
\makeatother
\defbeamertemplate{section in toc}{my toc}{%
\leavevmode\inserttocsectionnumber. {\color{normal text.fg}\inserttocsection}}
\defbeamertemplate{subsection in toc}{my toc}{%
\leavevmode\leftskip=2.5em{\color{structure.fg}\inserttocsectionnumber.\inserttocsubsectionnumber.} \inserttocsubsection\par}
\setbeamertemplate{sections/subsections in toc}[my toc]
\begin{document}
\renewcommand*\contentsname{Table of Contents}
\begin{frame}
\tableofcontents
\end{frame}
\begin{frame}{Reference}
\begin{block}{Table of Contents}
\begin{enumerate}[1.]
\item Motivation
\item Construction
\item The Method
\item Improvements
\item Applications
\begin{enumerate}[\theenumi.1.]
\item One
\item Two
\item Three
\end{enumerate}
\end{enumerate}
\end{block}
\end{frame}
\section{Motivation}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\section{Construction}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\section{The Method}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\section{Improvements}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\section{Applications}
\subsection{One}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\subsection{Two}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\subsection{Three}
\begin{frame}{Something}
\begin{block}{Something}
Something
\end{block}
\end{frame}
\end{document}
请注意,此代码不涵盖子小节,但如果您愿意,可以将其扩展到这些小节。