文章中的 Beamer 按钮

文章中的 Beamer 按钮

beamer我想使用 -class 产生与文档中与 -class相关的命令相同的结果article

\hyperlink{question}{\beamergotobutton{Allez à la question}}
\hyperlink{partie}{\beamerskipbutton{Sautez cette partie}}
\hyperlink{label}{\beamerreturnbutton{Retour}}

这将产生以下输出:

输出示例

有没有办法在一篇文章中获得相同的输出?

对于某些上下文,我想使用这些按钮将文档中的页面和文本段与我已经可以生成的超链接链接起来hyperref

答案1

只是为了好玩。我从beamer源文件中挑选了与“按钮”相关的定义,并\(def|use)beamertemplate用一些直接宏用法替换了工作人员。

Beamer 对圆角矩形的大小进行了硬编码(例如,尝试在下面的示例中替换\tiny\small,因此对于更灵活(但效率较低)的解决方案,具有形状的 tikz 节点rounded rectangle更好。

\documentclass{article}
\usepackage{tikz}
\usepackage{hyperref}

% copied from beamercolorthemedefault.sty
% begin
\definecolor{beamer@blendedblue}{rgb}{0.2,0.2,0.7}
% end

\colorlet{button}{beamer@blendedblue}
\colorlet{button border}{beamer@blendedblue}

\makeatletter
\newbox\beamer@tempbox
\newdimen\beamer@tempdim

% copied from beamerinnerthemedefault.sty
% begin
\newdimen\beamer@dima
\newdimen\beamer@dimb

%\defbeamertemplate*{button}{default}
\def\beamer@@tmpl@button
{%
  \setbox\beamer@tempbox=\hbox{{\insertbuttontext}}%
  \ht\beamer@tempbox=6pt%
  \dp\beamer@tempbox=0pt%
  \setbox\beamer@tempbox=\vbox{\box\beamer@tempbox\vskip2pt}%
  \beamer@tempdim=\wd\beamer@tempbox%
  \beamer@dima=\beamer@tempdim\advance\beamer@dima by2.2pt
  \beamer@dimb=\beamer@tempdim\advance\beamer@dimb by4pt
  \begin{pgfpicture}{-4pt}{0pt}{\the\beamer@tempdim}{8pt}
%    \color{bg}
    \pgfsetfillcolor{button}
    \pgfsetlinewidth{0.8pt}
    \pgfpathqmoveto{0pt}{0pt}
    \pgfpathqcurveto{-2.2pt}{0pt}{-4pt}{1.8pt}{-4pt}{4pt}
    \pgfpathqcurveto{-4pt}{6.2pt}{-2.2pt}{8pt}{0pt}{8pt}
    \pgfpathlineto{\pgfpoint{\the\beamer@tempdim}{8pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dima}{8pt}}%
    {\pgfpoint{\the\beamer@dimb}{6.2pt}}%
    {\pgfpoint{\the\beamer@dimb}{4pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dimb}{1.8pt}}%
    {\pgfpoint{\the\beamer@dima}{0pt}}%
    {\pgfpoint{\the\beamer@tempdim}{0pt}}
    \pgfpathclose
    \pgfusepathqfill
%    \colorlet{bg}{parent.bg}
%    \usebeamercolor[fg]{button border}
    \pgfsetstrokecolor{button border}
    \pgfpathqmoveto{0pt}{0pt}
    \pgfpathqcurveto{-2.2pt}{0pt}{-4pt}{1.8pt}{-4pt}{4pt}
    \pgfpathqcurveto{-4pt}{6.2pt}{-2.2pt}{8pt}{0pt}{8pt}
    \pgfpathlineto{\pgfpoint{\the\beamer@tempdim}{8pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dima}{8pt}}%
    {\pgfpoint{\the\beamer@dimb}{6.2pt}}%
    {\pgfpoint{\the\beamer@dimb}{4pt}}
    \pgfpathcurveto%
    {\pgfpoint{\the\beamer@dimb}{1.8pt}}%
    {\pgfpoint{\the\beamer@dima}{0pt}}%
    {\pgfpoint{\the\beamer@tempdim}{0pt}}
    \pgfpathclose
    \pgfusepathqstroke
  \end{pgfpicture}%
  \hskip-\beamer@tempdim%
  \box\beamer@tempbox%
  \kern4pt%
}
% end

% copied from beamerbasenavigation.sty
% begin
\pgfdefobject{beamergotosymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{5pt}{5pt}}
{
  \pgfpathqmoveto{1.5bp}{0.5bp}
  \pgfpathqlineto{3.5bp}{2bp}
  \pgfpathqlineto{1.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertgotosymbol{%
  \begin{pgfpicture}{1pt}{0pt}{6pt}{5pt}
    \pgfuseobject{beamergotosymbol}%
  \end{pgfpicture}}

\pgfdefobject{beamerskipsymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{7pt}{5pt}}
{
  \pgfpathqmoveto{1.5bp}{0.5bp}
  \pgfpathqlineto{3.5bp}{2bp}
  \pgfpathqlineto{1.5bp}{3.5bp}
  \pgfpathqmoveto{3.5bp}{0.5bp}
  \pgfpathqlineto{5.5bp}{2bp}
  \pgfpathqlineto{3.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertskipsymbol{%
  \begin{pgfpicture}{1pt}{0pt}{8pt}{5pt}
    \pgfuseobject{beamerskipsymbol}%
  \end{pgfpicture}}


\pgfdefobject{beamerreturnsymbol}{\pgfpoint{0pt}{-1pt}}{\pgfpoint{5pt}{5pt}}
{
  \pgfpathqmoveto{3.5bp}{0.5bp}
  \pgfpathqlineto{1.5bp}{2bp}
  \pgfpathqlineto{3.5bp}{3.5bp}
  \pgfusepathqfill
}

\def\insertreturnsymbol{%
  \begin{pgfpicture}{1pt}{0pt}{6pt}{5pt}
    \pgfuseobject{beamerreturnsymbol}%
  \end{pgfpicture}}


%\def\beamerbutton#1{\def\insertbuttontext{#1}\usebeamertemplate**{button}}
\def\beamerbutton#1{%
  \def\insertbuttontext{#1}%
  {\sffamily\tiny\color{white}\beamer@@tmpl@button}}
\def\beamergotobutton#1{\beamerbutton{\insertgotosymbol#1}}
\def\beamerskipbutton#1{\beamerbutton{\insertskipsymbol#1}}
\def\beamerreturnbutton#1{\beamerbutton{\insertreturnsymbol#1}}
% end
\makeatother

\newcommand{\myhyperlink}[2]{%
  {\hypersetup{hidelinks}\hyperlink{#1}{#2}}}

\begin{document}
\myhyperlink{question}{\beamergotobutton{Allez à la question}}
\myhyperlink{partie}{\beamerskipbutton{Sautez cette partie}}
\myhyperlink{label}{\beamerreturnbutton{Retour}}
\end{document}

在此处输入图片描述

答案2

您可以使用定制的方法实现类似的目的tcolorbox

在此处输入图片描述

\documentclass{article}
\usepackage{amssymb}

\usepackage[most]{tcolorbox}

\definecolor{myblue}{RGB}{153,153,217}
\newtcbox{\inlinebox}[1][]{enhanced,
                           box align=base,
                           nobeforeafter,
                           colback=myblue,
                           size=small,
                           boxrule=0pt,
                           left=0pt, right=0pt,
                           boxsep=2pt,
                           arc=5pt,
                           fontupper=\color{white},
                           #1}

\newcommand{\mylinkbox}[1]{\inlinebox{$\blacktriangleright$  \nameref{#1}}}

\usepackage{nameref}
\usepackage[hidelinks]{hyperref}

\begin{document}
\section{first section}\label{sec:example}
\newpage
Some regular text and a link box: \mylinkbox{sec:example} more regular text
\end{document}

相关内容