Vim beamer: dynamic frame title - latex

I am trying to create a new command in Latex Beamer to automatically add the frame title and subtitle with respected to section and subsection. In general, my command will look like:
\newcommand {\myframe}[1] {
\begin{frame}
if in a section {
\frametitle{\secname}
}
if in a subsection {
\framesubtitle{\subsecname}
}
#1
\end{frame}
}
How can I detect whether the frame is in a section or subsection?

You can add conditionals to the \section and \subsection command, which you can use to test within your \myframe macro:
\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}

Related

How to set text margin without conflict with block environment?

I want to decrease the margin between the content text and the page edge. I follow the method from: https://tex.stackexchange.com/questions/354022/modifying-the-margins-of-all-slides-in-beamer by using \setbeamersize{text margin left=1.40mm, text margin left=1.40mm}.
However, it will make the block not centered in the slide. Thus, how do I set the text margin without influencing the setting of the block?
Is there another way to set the text margin?
The full scripts as follows:
\documentclass[t]{beamer}
\usetheme{Madrid}
\usecolortheme{beaver}
\usefonttheme{structurebold}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{multicol}
\title[Short title]{Full Title of the Talk}
\author{JJ XX}
\institute[UCLA]
{
University of California \\
\medskip
\textit{jx#111.com}
}
\date{\today}
% set the text margin
\setbeamersize{text margin left=1.40mm, text margin left=1.40mm}
\settowidth{\leftmargini}{\usebeamertemplate{itemize item}}
\settowidth{\leftmargini}{\usebeamertemplate{enumerate item}}
\addtolength{\leftmargini}{-0.2\labelsep}
\begin{document}
\begin{frame}
\titlepage % Print the title page as the first slide
\end{frame}
\begin{frame}
\frametitle{Contents}
\begin{multicols}{2}
\tableofcontents
\end{multicols}
\end{frame}
\section{blocka}
\begin{frame}
\frametitle{blocka}
\begin{itemize}
\item First
\item Second
\end{itemize}
\begin{exampleblock}{Introduction to Beamer}
Beamer is a class of \LaTeX.
\end{exampleblock}
\end{frame}
\section{blockb}
\begin{frame}
The second example.
\frametitle{blockb}
\begin{block}{Beamer Intro}
New is New.
\end{block}
\end{frame}
The margins of beamer blocks are designed in such a way that the text within the block is still aligned with the surrounding text. If you set the margin independently, this will break this alignment:
\documentclass[t]{beamer}
\usetheme{Madrid}
\usecolortheme{beaver}
\setbeamersize{text margin left=1.40mm, text margin left=1.40mm}
\makeatletter
\setbeamertemplate{block begin}
{%
\par\vskip\medskipamount%
\hfill\begin{minipage}{.98\textwidth}%
\begin{beamerboxesrounded}[upper=block title,lower=block body,shadow=true]%
{\raggedright\usebeamerfont*{block title}\insertblocktitle}%
\raggedright%
\usebeamerfont{block body}%
}
\setbeamertemplate{block end}
{\end{beamerboxesrounded}\end{minipage}\vskip\smallskipamount}
\makeatother
\begin{document}
\begin{frame}
The second example.
\frametitle{blockb}
\begin{block}{Beamer Intro}
New is New.
\end{block}
\end{frame}
\end{document}
Alternatively, you could use the tcolorbox inner theme:
\documentclass[t]{beamer}
\usetheme{Madrid}
\usecolortheme{beaver}
\setbeamersize{text margin left=1.40mm, text margin left=1.40mm}
\useinnertheme{tcolorbox}
\tcbset{
center,
width=\linewidth
}
\begin{document}
\begin{frame}
The second example.
\frametitle{blockb}
\begin{block}{Beamer Intro}
New is New.
\end{block}
\end{frame}
\end{document}

Beamer Slide header is not including subsubsection

I am using beamer to make my slides. I managed to have the subsections show in the header. For example subsection of Security is (1) Background (2) PerSpectron (3) Commercial ....
How can I add subsubsections in the header too? For example, I want to have several subsections to the background appear in an extra column in the header, similar to subsections. Is there any way to do this? Thank you.
First I'd like to quote the beamer users guide:
"Do not use subsubsections, they are evil."
If you want to torture your audience, you can use this quick hack. Make sure that:
you have more sections/subsections than subsubsections, otherwise the height might be wrong
you set the counter for the number of subsubsection in each subsection
\documentclass{beamer}
\usetheme{Warsaw}
\usepackage{pgffor}
\newcounter{totalsubsub}
\AtBeginSubsubsection[]{\label{subsubsec:\thesection:\thesubsection:\thesubsubsection}}
\makeatletter
\setbeamertemplate{headline}{%
\leavevmode%
\#tempdimb=2.4375ex%
\ifnum\beamer#subsectionmax<\beamer#sectionmax%
\multiply\#tempdimb by\beamer#sectionmax%
\else%
\multiply\#tempdimb by\beamer#subsectionmax%
\fi%
\ifdim\#tempdimb>0pt%
\advance\#tempdimb by 1.825ex%
\begin{beamercolorbox}[wd=.33\paperwidth,ht=\#tempdimb]{section in head/foot}%
\vbox to\#tempdimb{\vfil\insertsectionnavigation{.33\paperwidth}\vfil}%
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.34\paperwidth,ht=\#tempdimb]{subsection in head/foot}%
\vbox to\#tempdimb{\vfil\insertsubsectionnavigation{.33\paperwidth}\vfil}%
\end{beamercolorbox}%
\begin{beamercolorbox}[leftskip=3.3ex,wd=.33\paperwidth,ht=\#tempdimb]{section in head/foot}%
\begin{minipage}[b][\#tempdimb][c]{.9\linewidth}%
\ifnum\thetotalsubsub>0
\foreach \i in {1,...,\thetotalsubsub}{%
\ifnum\i=\thesubsubsection
\usebeamercolor[fg]{subsubsection in sidebar}
\else
\usebeamercolor[fg]{subsubsection in sidebar shaded}
\fi
\hyperlink{subsubsec:\thesection:\thesubsection:\i}{\nameref{subsubsec:\thesection:\thesubsection:\i}}\par
}
\fi
\end{minipage}%
\end{beamercolorbox}%
\fi%
}
\makeatother
\begin{document}
\section{section}
\subsection{sub 1}
\setcounter{totalsubsub}{3}
\subsubsection{subsub 1}
\begin{frame}
subsub 1
\end{frame}
\subsubsection{subsub 2}
\begin{frame}
subsub 2
\end{frame}
\subsubsection{subsub 3}
\begin{frame}
subsub 3
\end{frame}
\subsection{sub 2}
\setcounter{totalsubsub}{0}
\begin{frame}
abc
\end{frame}
\subsection{sub 3}
\setcounter{totalsubsub}{2}
\begin{frame}
content...
\end{frame}
\subsubsection{subsub 1}
\begin{frame}
subsub 1
\end{frame}
\subsubsection{subsub 2}
\begin{frame}
subsub 2
\end{frame}
\end{document}

Switch Overlay Specification in Latex Beamer

I have a beamer document with
\beamerdefaultoverlayspecification{<+->}
in the preamble to make \items appear separately. However, this seems to also make \bibitems
appear separately. How can I switch back to 'normal' within the document, such that all bibitems appear on one slide?
You can change the default overlay specification before the bibliography:
\documentclass{beamer}
\usepackage{biblatex}
\addbibresource{biblatex-examples.bib}
\beamerdefaultoverlayspecification{<+->}
\begin{document}
\begin{frame}
\begin{itemize}
\item content...
\item content...
\end{itemize}
\end{frame}
\beamerdefaultoverlayspecification{}
\begin{frame}
\nocite{knuth:ct,angenendt}
\printbibliography
\end{frame}
\end{document}

citation, tables and equation exceed page width in beamer

I am using Latex for the first time and I am preparing a slide using 'beamer'. What happening is that some of my citations, tables and long equations are exceeding beyond the text width, though it wasn't the problem when the document class was 'article'. My tables aren't long, as one of them has only 3 rows and 6 columns.
The latex codes are
\documentclass[9pt]{beamer}
\mode<presentation> {
\usefonttheme{serif}
\usetheme{Madrid}
\definecolor{BlueGreen}{cmyk}{0.85,0,0.33,0}
\colorlet{beamer#blendedblue}{BlueGreen!120}}
\usepackage{booktabs}
\usepackage{caption}
\hypersetup{pdfnewwindow}
\setbeamertemplate{caption}[numbered]
\setbeamerfont{frametitle}{size=\footnotesize}
\setbeamertemplate{navigation symbols}{}
\setbeamercolor{postit}{bg=violet!110}
\usepackage{ragged2e} %new code
\addtobeamertemplate{block begin}{}{\justifying}
\usepackage{textpos}
\begin{document}
\begin{frame} \frametitle{\textbf{{\Large Objective}}}
\begin{itemize}
\justifying
\item This package gives you easy access to the Lorem Ipsum dummy text; an option is available to separate the paragraphs of the dummy text. This text \cite{kumar2015method}.
\item The long equation is:
\begin{equation}
A(\theta,\alpha) = \dfrac{ A*{-(\alpha*A)}\beta*{(\delta-1)} \left(A* \hspace{1mm}\hspace{1mm}C^{-A Z_{H}} \hspace{1mm}C^{-C^{-A *Z_{H}}} \prod_{i=1}^{m-1} \left( \dfrac{ A \hspace{1mm}C^{-A* Z_{u(i)}} C^{-C^{-A* Z_{u(i)}}}}{1- \frac{1}{C-1} (C^{1-C^{-A Z_{u(i)}}}-1)}\right) \right) }{ \int_{0}^{\infty} C^{-(\alpha *A)}(A^{(\beta-1)} \left( A* \hspace{1mm}\hspace{1mm}C^{-A Z_{H}} \hspace{1mm}C^{-C^{-A Z_{H}}} \prod_{i=1}^{B-1} \left(\dfrac{ A \hspace{1mm}C^{-A Z_{u(i)}} C^{-C^{-A* Z_{u(i)}}}}{1- \frac{1}{C-1} (C^{1-C^{-A* Z_{u(i)}}}-1)}\right) \right) A} .
\end{equation}
\end{itemize}
\end{frame}
\bibliography{ref}
\bibliographystyle{plainnat}
\end{document}
And the contents of the .bib file is:
#article{kumar2015method,
title={This is the title of the article},
author={Kumar, Dinesh and others},
journal={This is Journal},
volume={2},
number={3},
pages={150-180},
year={2015}
}
If you use the plainnat bib style, you should also load the natbib package. This will automatically allow line breaks
you don't need the caption package, beamer provides it's own mechanism to customise captions
you must place the bibliography inside a frame
for the very large equation, I would suggest to replace the fraction with (...) \times (...)^{-1}, this way you can split it over multiple lines. In addition you'll probably want to use a smaller font size and maybe remove all the manual spaces.
\documentclass[9pt]{beamer}
\mode<presentation> {
\usefonttheme{serif}
\usetheme{Madrid}
\definecolor{BlueGreen}{cmyk}{0.85,0,0.33,0}
\makeatletter
\colorlet{beamer#blendedblue}{BlueGreen!120}
\makeatother
}
\usepackage{booktabs}
%\usepackage{caption}
\hypersetup{pdfnewwindow}
\setbeamertemplate{caption}[numbered]
\setbeamerfont{frametitle}{size=\footnotesize}
\setbeamertemplate{navigation symbols}{}
\setbeamercolor{postit}{bg=violet!110}
\usepackage{ragged2e} %new code
\addtobeamertemplate{block begin}{}{\justifying}
\usepackage{natbib}
\usepackage{textpos}
\begin{document}
\begin{frame} \frametitle{\textbf{{\Large Objective}}}
\begin{itemize}
\justifying
\item This package gives you easy access to the Lorem Ipsum dummy text; an option is available to separate the paragraphs of the dummy text. This text \cite{kumar2015method}.
\item The long equation is:
\end{itemize}
\end{frame}
\begin{frame}
\bibliography{ref}
\bibliographystyle{plainnat}
\end{frame}
\end{document}

Latex Beamer: Increase spacing between sections in section navigation bar

I would like to modify my Latex Beamer Template.
Hence, I would like to increase the space between the displayed sections in the section navigation bar. At the moment the are left indented but the sections are way to close together.
I use the following code to generate the headline:
setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=3ex,dp=1.125ex]{palette tertiary}%
\insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
\end{beamercolorbox}%
}
}
How can I modify the spacing between the displayed section?
The tipple fill plus1filll you insert after the navigation makes it flush left. If you remove it, the sections will automatically be distributed within the available paper width:
\documentclass{beamer}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=3ex,dp=1.125ex]{palette tertiary}%
\insertsectionnavigationhorizontal{\paperwidth}{}{}
\end{beamercolorbox}%
}
}
\begin{document}
\section{title}
\begin{frame}
content...
\end{frame}
\section{title}
\begin{frame}
content...
\end{frame}
\end{document}
If you want to keep the sections flush left and just add some additional space between:
\documentclass{beamer}
\setbeamertemplate{headline}{%
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=\paperwidth,ht=3ex,dp=1.125ex]{palette tertiary}%
\insertsectionnavigationhorizontal{\paperwidth}{}{\hskip0pt plus1filll}
\end{beamercolorbox}%
}
}
\setbeamertemplate{section in head/foot}{\insertsectionhead\hspace{0.5cm}}
\begin{document}
\section{title}
\begin{frame}
content...
\end{frame}
\section{title}
\begin{frame}
content...
\end{frame}
\end{document}

Resources