在标题中添加三角形以指向图形(tufte 类)

在标题中添加三角形以指向图形(tufte 类)

我正在使用 Tufte 类来处理包含大量图片的文档,我的一些读者抱怨说,找到不在页边距中的图片的标题并不总是那么容易。因此,我想定义(然后使用)宏变体,\caption在标题前面显示一个小三角形,指向图片。例如\captiondown{my caption}将显示“▼ 数字3:我的标题”。

我不清楚如何编写这样的宏。我以为我可以通过重新定义来实现这一点\figurename,但看下面的例子,它在环境中有效marginfigure,而不是在figurefigure*环境中。有人能帮忙吗?

\documentclass[a4paper,nobib]{tufte-handout}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{showframe}

\renewcommand{\figurename}{\textbf{Figure}}

\begin{document}
\begin{marginfigure}
  \tikz\fill[cyan] rectangle(\marginparwidth,2);
  \renewcommand{\figurename}{$\blacktriangle$~\textbf{Figure}}
  \caption{Some caption for the blue figure.}
\end{marginfigure}
\begin{figure}
  \tikz\fill[yellow]rectangle(\textwidth,4);
  \renewcommand{\figurename}{$\blacktriangleleft$~\textbf{Figure}} %ignored?
  \caption[][3cm]{Some caption for the yellow figure.}
\end{figure}
\begin{figure*}
  \tikz\fill[magenta]rectangle(\textwidth,3);
  \renewcommand{\figurename}{$\blacktriangledown$~\textbf{Figure}} %ignored?
  \caption[][-4.5cm]{Some caption for the magenta figure.}
\end{figure*}
\end{document}

输出

更新:

这是我重新定义的变体。如果我在and环境\fnum@figure之前重新定义该宏,我会得到所需的输出,所以我想我会用这个方法。figurefigure*

我仍然非常希望能够\captiondown{my caption}在这些环境中进行调用,但我不知道如何做到这一点。

\documentclass[a4paper,nobib]{tufte-handout}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{showframe}

\makeatletter
\newcommand{\captionsbelow}{%
  \renewcommand{\fnum@figure}{$\blacktriangle$~\textbf{\figurename}~\thefigure}}
\newcommand{\captionsright}{%
  \renewcommand{\fnum@figure}{$\blacktriangleleft$~\textbf{\figurename}~\thefigure}}
\newcommand{\captionsabove}{%
  \renewcommand{\fnum@figure}{$\blacktriangledown$~\textbf{\figurename}~\thefigure}}
\makeatother

\begin{document}
\captionsbelow
\begin{marginfigure}
  \tikz\fill[cyan] rectangle(\marginparwidth,2);
  \caption{Some caption for the blue figure.}
\end{marginfigure}
\captionsright
\begin{figure}
  \tikz\fill[yellow]rectangle(\textwidth,4);
  \caption[][3cm]{Some caption for the yellow figure.}
\end{figure}
\captionsabove
\begin{figure*}
  \tikz\fill[magenta]rectangle(\textwidth,3);
  \caption[][-4.5cm]{Some caption for the magenta figure.}
\end{figure*}
\end{document}

输出

最后更新

使用我得到的所有输入,设法修补 Tufte 定义,以便根据图形的位置在每个浮点中重新定义方向。(我只是不关心正反面模式,我不使用它,但扩展它以支持它应该不是问题。)

\documentclass[a4paper,nobib]{tufte-handout}
\usepackage{showframe}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{etoolbox}

\makeatletter
\renewcommand{\fnum@figure}{\captiontriangle~\textbf{\figurename}~\thefigure}
\newcommand{\captionbelow}{\gdef\captiontriangle{$\blacktriangle$}}
\newcommand{\captionright}{\gdef\captiontriangle{$\blacktriangleleft$}}
\newcommand{\captionabove}{\gdef\captiontriangle{$\blacktriangledown$}}
% Use \captionbelow by default, for margin figures
\AtBeginDocument{\captionbelow}
\AfterEndEnvironment{@tufte@float}{\captionbelow}
% automatically change the triangle for other captions
\AtEndEnvironment{@tufte@float}{%
  \ifthenelse{\boolean{@tufte@float@star}}%
    {\ifthenelse{\equal{\floatalignment}{b}}{\captionabove}{\captionbelow}}%
    {\captionright}}
\makeatother

\setcounter{totalnumber}{4}% for demonstration
\begin{document}
\begin{marginfigure}
  \tikz\fill[cyan] rectangle(\marginparwidth,2);
  \caption{Some caption for the blue figure.}
\end{marginfigure}
\begin{figure}
  \tikz\fill[yellow]rectangle(\textwidth,4);
  \caption[][3cm]{Some caption for the yellow figure.}
\end{figure}
\begin{figure*}
  \tikz\fill[magenta]rectangle(\textwidth,3);
  \setfloatalignment{b} %force caption above
  \caption{Some caption for the magenta figure.}
\end{figure*}
\begin{figure*}
  \tikz\fill[green!30]rectangle(\textwidth,3);
  \caption[][-1.2em]{Some caption for the green figure.}
\end{figure*}
\begin{figure*}[b]
  \tikz\fill[gray!30]rectangle(\textwidth,3);
  \caption{Some caption for the gray figure.}
\end{figure*}
\end{document}

在此处输入图片描述

答案1

解决此问题的一个好方法是定义一个重置图形标签的命令。之后,在每个and环境之后使用\AfterEndEnvironment(from ) 执行此类命令。这样,您也许能够重新定义标题的外观,但在环境结束后仍能获得图形标题的原始定义。etoolboxfigurefigure*

\documentclass[a4paper,nobib]{tufte-handout}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{showframe}

\usepackage{etoolbox}

\makeatletter
    \renewcommand{\fnum@figure}{\textbf{\figurename}~\thefigure}
    % save older version of \fnum@figure
    \let \fnum@figureold \fnum@figure
    % define a command to reset to the older version
    \newcommand{\resetfnumfigure}{\let \fnum@figure \fnum@figureold}
\makeatother

\AfterEndEnvironment{figure}{\resetfnumfigure}
\AfterEndEnvironment{figure*}{\resetfnumfigure}


\makeatletter
    \newcommand{\captionsbelow}{%
      \renewcommand{\fnum@figure}{$\blacktriangle$~\textbf{\figurename}~\thefigure}}
    \newcommand{\captionsright}{%
      \renewcommand{\fnum@figure}{$\blacktriangleleft$~\textbf{\figurename}~\thefigure}}
    \newcommand{\captionsabove}{%
      \renewcommand{\fnum@figure}{$\blacktriangledown$~\textbf{\figurename}~\thefigure}}
\makeatother

\begin{document}

\begin{marginfigure}
    \captionsbelow
  \tikz\fill[cyan] rectangle(\marginparwidth,2);
  \caption{Some caption for the blue figure.}
\end{marginfigure}
\captionsright
\begin{figure}
  \tikz\fill[yellow]rectangle(\textwidth,4);
  \caption[][3cm]{Some caption for the yellow figure.}
\end{figure}
\captionsabove
\begin{figure*}
  \tikz\fill[magenta]rectangle(\textwidth,3);
  \caption[][-4.5cm]{Some caption for the magenta figure.}
\end{figure*}

\end{document}

相关内容