将投影仪框架标题放入左上角的平行四边形中

将投影仪框架标题放入左上角的平行四边形中

我正在尝试将每个框架的标题放置在一个可调整标题长度的平行四边形中。我希望平行四边形从每个框架的相同位置开始,例如,从左上角开始,向左和上边框稍微偏移。我在放置方面遇到了问题,长标题超出了边缘。到目前为止,我得到了以下信息:

\documentclass[10pt,xcolor=svgnames]{beamer}

\setbeamercolor{background canvas}{bg=Green!10}
\setbeamercolor{frametitle}{fg=Brown,bg=Yellow!20}
\setbeamercolor{normal text}{bg=DarkBlue}


\usepackage{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}

\makeatletter

\setbeamertemplate{frametitle}{%
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{tikzpicture}[remember picture,overlay]
  \tikzstyle{every node}=[trapezium, minimum width=0cm, minimum height=0cm, 
  trapezium left angle=70, trapezium right angle=110, fill=Gray!20]
  
  \node[inner xsep=2pt] at ($(current page.north west)+(1cm,-1cm)$){
    \usebeamerfont{frametitle}%
    \strut\insertframetitle\strut\par%
  };  
  \end{tikzpicture}
}

\makeatother

\begin{document}
\begin{frame}\frametitle{This is a test title!}
\end{frame}
\begin{frame}\frametitle{Short}
\end{frame}
\end{document}

答案1

您可以使用该anchor选项来定义节点应锚定在哪个站点:

\documentclass[10pt,xcolor=svgnames]{beamer}

\setbeamercolor{background canvas}{bg=Green!10}
\setbeamercolor{frametitle}{fg=Brown,bg=Yellow!20}
\setbeamercolor{normal text}{bg=DarkBlue}


\usepackage{tcolorbox}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}

\makeatletter

\setbeamertemplate{frametitle}{%
  \ifbeamercolorempty[bg]{frametitle}{}{\nointerlineskip}%
  \@tempdima=\textwidth%
  \advance\@tempdima by\beamer@leftmargin%
  \advance\@tempdima by\beamer@rightmargin%
  \begin{tikzpicture}[remember picture,overlay]
  \tikzset{every node/.style={trapezium, minimum width=0cm, minimum height=0cm, 
  trapezium left angle=70, trapezium right angle=110, fill=Gray!20}}
  
  \node[inner xsep=2pt,anchor=west] at ($(current page.north west)+(0.2cm,-1cm)$){
    \usebeamerfont{frametitle}%
    \strut\insertframetitle\strut\par%
  };  
  \end{tikzpicture}
}

\makeatother

\begin{document}
\begin{frame}\frametitle{This is a test title!}
\end{frame}
\begin{frame}\frametitle{Short}
\end{frame}
\end{document}

在此处输入图片描述

相关内容