
スライドごとに 1 つの図を含む多数のフレームを持つプレゼンテーションを作成しています。そのため、同じコードを何百回も繰り返す代わりに、\newcommand
引数の 1 つが図の名前である単純な for を作成しました。この引数は図のラベルとしても使用されます。ただし、図のサブフォルダーを使用する場合、引数は次のようになります。ただし、図のラベルとしてのみsubfolderone/subfoldertwo/figurename
使用したいのです。figurename
引数 #1 を「/」で区切って、最後の引数のみをラベル付けに使用することは可能ですか? そうでなければ、別の入力引数を作成します。
\documentclass{beamer}
\usepackage{graphicx}
\newcommand{\figcaptiontitlecrop}[7]{%
\begin{frame}[b]{#3}
\begin{figure}
\centering
\includegraphics[trim=#4mm #5mm #6mm #7mm, clip]{#1}
\caption{#2}%
\label{fig:#1}%
\end{figure}
\end{frame}
}
\begin{document}
\figcaptiontitlecrop{filename}{Caption Text}{Frame Title Here}{0}{0}{0}{0}
%\figcaptiontitlecrop{figures/subfolder/filename}{Caption Text}{Frame Title Here}{0}{0}{0}{0}
\end{document}
答え1
7 つの引数を持つコマンドは避けてください。キー値アプローチの方が適しています。
\documentclass{beamer}
\usepackage{graphicx}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\beamerfigure}{mm}
{
\begin{frame}[b]
\keys_set:nn { bjartmar/beamerfigure } { #1 }
\frametitle{\l_bjartmar_beamerfigure_title_tl}
\begin{figure}
\centering
\use:x
{
\exp_not:N \includegraphics [
\l_bjartmar_beamerfigure_options_tl,
trim=\l_bjartmar_beamerfigure_tl,
clip
]
}{\l_bjartmar_beamerfigure_path_tl / \l_bjartmar_beamerfigure_name_tl}
\caption{#2}
\label{fig:\l_bjartmar_beamerfigure_name_tl}
\end{figure}
\end{frame}
}
\keys_define:nn { bjartmar/beamerfigure }
{
title .tl_set:N = \l_bjartmar_beamerfigure_title_tl,
path .tl_set:N = \l_bjartmar_beamerfigure_path_tl,
path .initial:n = {.},
name .tl_set:N = \l_bjartmar_beamerfigure_name_tl,
options .tl_set:N = \l_bjartmar_beamerfigure_options_tl,
trim .tl_set:N = \l_bjartmar_beamerfigure_tl,
trim .initial:n = 0~0~0~0,
}
\ExplSyntaxOff
\begin{document}
\beamerfigure{
name=donald-duck,
options={height=.5\textheight},
trim=0 5 0 5,
}{This is Donald Duck}
\beamerfigure{
path=/usr/local/texlive/2016/texmf-dist/tex/latex/mwe/,
name=example-grid-100x100pt,
}{Another figure}
\end{document}
が指定されていない場合はpath
、現在のディレクトリが使用されます。 ご覧のとおり、 の追加オプションを指定することもできます\includegraphics
。