2016-03-05 55 views
0

我正在嘗試在Latex Beamer中創建一個新的命令,以便自動將幀標題和副標題添加到尊重部分和子部分。在一般情況下,我的命令看起來像:Vim beamer:動態幀標題

\newcommand {\myframe}[1] { 
    \begin{frame} 
    if in a section { 
     \frametitle{\secname} 
    } 
    if in a subsection { 
     \framesubtitle{\subsecname} 
    } 
    #1 
    \end{frame} 
} 

如何檢測幀是否是在一節或小節?

回答

0

您可以添加條件語句的\section\subsection命令,你可以用它來測試內的\myframe宏:

enter image description here

\documentclass{beamer} 

\let\Tiny\tiny% http://tex.stackexchange.com/a/94159/5764 

\newif\ifinsection 
\newif\ifinsubsection 

\let\oldsection\section 
\renewcommand{\section}{% 
    \global\insectiontrue% In section 
    \global\insubsectionfalse% Not in subsection 
    \oldsection} 
\let\oldsubsection\subsection 
\renewcommand{\subsection}{% 
    %\global\insectionfalse% No in section 
    \global\insubsectiontrue% In subsection 
    \oldsubsection} 

\newcommand {\myframe}[1] {% 
    \begin{frame} 
    \ifinsection\frametitle{\secname}\fi 
    \ifinsubsection\framesubtitle{\subsecname}\fi 
    #1 
    \end{frame} 
} 

\begin{document} 

\begin{frame} 
    \frametitle{A frame} 
\end{frame} 

\section{A section} 

\myframe{Some content} 

\subsection{A subsection} 

\myframe{Some content} 

\end{document}