我一直在寻找,似乎侧边栏格式是 Beamer 的内置格式。我该如何更改格式,以便将其表示为tree
类似输出?
编辑:MWE如下:
\documentclass[presentation]{beamer}
\usepackage[english]{babel}
\usetheme{Singapore}
\useoutertheme{sidebar}
\usecolortheme{rose}
\setbeamercovered{transparent}
\beamertemplatenavigationsymbolsempty
\begin{document}
\section{Section1}
\subsection{Subsection1}
\begin{frame}
First frame without title.
\end{frame}
\subsection{Subsection2}
\begin{frame}
Second frame without title.
\end{frame}
\section{Section2}
\subsection{Subsection1}
\begin{frame}
Third frame without title.
\end{frame}
\subsection{Subsection2}
\begin{frame}
Fourth frame without title.
\end{frame}
\end{document}
这完美地完成了两件事 - 它在每张幻灯片的侧面显示所有标题和副标题。它还将当前幻灯片设置为粗体。
不过,也出现了一些问题。首先,它只显示章节和子章节(而不是子子章节)。其次,它没有左侧的栏来创建树。我也见过树型,但在幻灯片顶部就像这里一样。以下是我想在侧边栏获取的内容:
├── blank
│ ├── defaults
│ ├── files
│ ├── handlers
│ ├── LICENSE
│ ├── meta
│ ├── README.md
│ ├── tasks
│ ├── templates
│ └── vars
└── Blank
├── ansible.cfg
├── dev
│ ├── group_vars
│ │ └── all
│ └── hosts
├── LICENSE
├── plays
├── prod
│ ├── group_vars
│ │ └── all
│ └── hosts
├── README.md
├── requirements.yml
├── roles
│ ├── external
│ └── internal
│ └── blank
└── site.yml
答案1
\documentclass{beamer}
% total number of sections %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{totcount}
\newcounter{totalsection}
\regtotcounter{totalsection}
\AtBeginDocument{%
\pretocmd{\section}{\refstepcounter{totalsection}}{}{}%
}%
% number of subsections per section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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}
% Creating the sidebar
\usepackage{pmboxdraw}
\useoutertheme[height=0pt,left,width=.22\textwidth]{sidebar}
\setbeamercolor{sidebar}{use=structure,bg=structure.fg!20!white}
\setbeamercolor{section in sidebar}{fg=alerted text.fg}
\setbeamercolor{section in sidebar shaded}{fg=structure}
\setbeamercolor{subsection in sidebar}{fg=alerted text.fg!30!bg}
\setbeamercolor{subsection in sidebar shaded}{fg=structure}
\setbeamercolor{current subsection in sidebar}{fg=alerted text.fg}
\usepackage{pgffor}
\makeatletter
\setbeamertemplate{sidebar left}{%
\begin{beamercolorbox}[wd=\beamer@sidebarwidth,sep=2em]{sidebar}%
\usebeamerfont{section in sidebar}%
%
% parent = title %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\insertshorttitle\newline%
%
% first level = section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\foreach \i in {1,...,\totvalue{totalsection}}{%
% get number of subsections in current section
\setcounter{currentsub}{\ObtainTrackedValueExp[\i]{section}{subsection}}%
% insert vertical line + line to right |-
\ifnum\i=\totvalue{totalsection}%
\textSFii%
\else% shorter line for final section
\textSFviii%
\fi%
% insert horzonal line - or T if there are subsection
\ifnum\thecurrentsub>0%
\textSFvi%
\else%
\textSFx%
\fi%
% insert hoziontal line -
\textSFx~%
% insert hyperline to section
{%
\ifnum\i=\value{section}%
\usebeamercolor[fg]{section in sidebar}%
\else%
\usebeamercolor[fg]{section in sidebar shaded}%
\fi%
\mbox{\hyperlink{sec:\i}{\nameref{sec:\i}}}\newline%
}%
%
% secon level = subsection %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\ifnum\thecurrentsub>0%
\foreach \j in {1,...,\thecurrentsub}{%
% vertical line to connect section |
\ifnum\i<\totvalue{totalsection}%
\textSFxi%
\else%
\textcolor{bg}{\textSFxi}% not for the last section
\fi%
%
% insert vertical line + line to right |-
\ifnum\j=\thecurrentsub%
\textSFii%
\else% shorter line for final section
\textSFviii%
\fi%
% insert hoziontal line -
\textSFx\textSFx~%
% insert hyperline to section
{%
\ifnum\i=\value{section}%
\ifnum\j=\value{subsection}%
\usebeamercolor[fg]{current subsection in sidebar}%
\else%
\usebeamercolor[fg]{subsection in sidebar}%
\fi%
\else%
\usebeamercolor[fg]{subsection in sidebar shaded}%
\fi%
\mbox{\hyperlink{subsec:\i:\j}{\nameref{subsec:\i:\j}}}\newline%
}%
}%
\fi%
}%
\end{beamercolorbox}%
}%
\makeatother
\title{Some Title}
\begin{document}
\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 Three}
\frame{abc}
\subsection{subsection a}
\frame{abc}
\subsection{subsection b}
\frame{abc}
\subsection{subsection c}
\frame{abc}
\end{document}