投影机:\insertshortsection

投影机:\insertshortsection
\documentclass{beamer}

\begin{document}

\begin{frame}
\frametitle{Contents}
\tableofcontents
\end{frame}

\section[Sec. A]{Section A}
\subsection{SubSec a}
\begin{frame}
\frametitle{\insertsection: \insertsubsection}
\end{frame}

\subsection{SubSec b}
\begin{frame}
\frametitle{\insertsection: \insertsubsection}
\end{frame}

\section[Sec. B]{Section B}
\subsection{SubSec a}
\begin{frame}
\frametitle{\insertsection: \insertsubsection}
\end{frame}

\subsection{SubSec b}
\begin{frame}
\frametitle{\insertsection: \insertsubsection}
\end{frame}

\end{document}

  • 我经常使用\frametitle{\insertsection: \insertsubsection}(或类似) 来自动生成框架标题beamer
  • 有时我想使用标题的简短版本,例如\section[Sec. A]{Section A}-->\insertshortsection(= Sec. A)不可用(另请参阅这里)。

有没有简单的方法可以访问section和朋友的简短版本?我说的“简单”是指解决方案没有太多副作用。


可能相关


解决方案

\documentclass{beamer}

\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\xdef\myshortsec{#1}
\oldsection*{#2}%
}
\def\@StarredWithout#1{
\xdef\myshortsec{#1}
\oldsection*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\xdef\myshortsec{#1}
\oldsection[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\xdef\myshortsec{#1}
\oldsection{#1}%
}
\makeatother

\begin{document}

\begin{frame}
\frametitle{Contents}
\tableofcontents
\end{frame}

\section[Sec. A]{Section A}
\subsection{SubSec a}
\begin{frame}
\frametitle{\insertsection\ \texttt{(long)}: \myshortsec\ \texttt{(short)}: \insertsubsection}
\end{frame}

\subsection{SubSec b}
\begin{frame}
\frametitle{\insertsection\ \texttt{(long)}: \myshortsec\ \texttt{(short)}: \insertsubsection}
\end{frame}

\end{document}

在此处输入图片描述

答案1

您可以使用\insertsectionhead

\documentclass{beamer}

\begin{document}

\begin{frame}
\frametitle{Contents}
\tableofcontents
\end{frame}

\section[Sec. A]{Section A}
\subsection{SubSec a}
\begin{frame}
\frametitle{\insertsectionhead: \insertsubsection}
\end{frame}

\end{document}

在此处输入图片描述

答案2

以下是从这个答案中偷来的: https://tex.stackexchange.com/a/380116/120578

(这也是我的,并且至少用过 5-6 次来解决不同的问题,但出于某种原因仍然没有投票 :( :P)

\documentclass{beamer}

\let\oldsection\section
\makeatletter
\def\section{%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\xdef\myshortsec{#1}
\oldsection*{#2}%
}
\def\@StarredWithout#1{
\xdef\myshortsec{#1}
\oldsection*{#1}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\xdef\myshortsec{#1}
\oldsection[#1]{#2}%
}
\def\@nonStarredWithout#1{%
\xdef\myshortsec{#1}
\oldsection{#1}%
}
\makeatother

\begin{document}

\begin{frame}
\frametitle{Contents}
\tableofcontents
\end{frame}

\section[Sec. A]{Section A}
\subsection{SubSec a}
\begin{frame}
\frametitle{sect-\insertsection : short-\myshortsec: \insertsubsection}
\end{frame}

\subsection{SubSec b}
\begin{frame}
\frametitle{sect-\insertsection: short-\myshortsec : \insertsubsection}
\end{frame}


\end{document}

如果我们以这种方式重新定义分段命令,我们可以做很多事情来使用它们的参数,正如我在原始答案中注意到的那样:P

相关内容