表格中长箭头上的脚注

发布于 2021-11-18 22:38:02

想要在表格中,长箭头(xlongrightarrow) 上方的文字中增加一个脚注。

由于无法使用 \footnote ,我知道有两种备选,但都有问题:

  • 第一种方式的问题是,没有产生链接。
  • 第二种方式,会重复生成脚注。(如果将脚注写在长箭头后方,则不会有问题)
\documentclass[UTF8,11pt]{ctexart}
\usepackage{hyperref}
\usepackage{extarrows}
\usepackage{tablefootnote}
\begin{document}

\begin{tabular}{cc}
  a & b \\
  $\xlongrightarrow{x + y \footnotemark[1]}$ & d
\end{tabular}
\footnotetext[1]{note1}

\begin{table}[htbp]
  \begin{tabular}{cc}
    a & b \\
    $\xlongrightarrow{x + y \tablefootnote{note2}}$ & d
  \end{tabular}
\end{table}

\end{document}

查看更多

关注者
0
被浏览
1.3k
雾月
雾月 2021-11-19
这家伙很懒,什么也没写!

出现这种情况是因为 extarrows 宏包内部使用了 amsmath 宏包的 \ext@arrow 命令,该命令的第 #6#7 参数对应于 \xlongrightarrow[<#6>]{<#7>}。只是这 #6#7 会被使用两次,一次用于测量盒子的宽度,另一次则用于输出。(见 \ext@arrow 的定义,位于 amsmath.sty

知道这个就容易修改了:

\makeatletter
\newif\ifext@arrow@measuring@
\let\saved@ext@arrow\ext@arrow % 保存原始定义
\def\ext@arrow#1#2#3#4#5#6#7{%
  \mathrel{\mathop{%
    \setbox\z@\hbox{#5\displaystyle}%
    \ext@arrow@measuring@true% 增加一个
    \setbox\tw@\vbox{\m@th
      \hbox{$\scriptstyle\mkern#3mu{#6}\mkern#4mu$}%
      \hbox{$\scriptstyle\mkern#3mu{#7}\mkern#4mu$}%
      \copy\z@
    }%
    \hbox to\wd\tw@{\unhbox\z@}}%
  \ext@arrow@measuring@false% 增加一个,实际上是不需要的,由于 \mathop 构建一个组
  \limits
    \@ifnotempty{#7}{^{\if0#1\else\mkern#1mu\fi
                       #7\if0#2\else\mkern#2mu\fi}}%
    \@ifnotempty{#6}{_{\if0#1\else\mkern#1mu\fi
                       #6\if0#2\else\mkern#2mu\fi}}}%
}
% 直接写 \def\arrowmeasuring#1#2{\ifext@arrow@measuring#1\else#2\fi} 也可以
\def\arrowmeasuring{\ifext@arrow@measuring@\expandafter\@firstoftwo\else\expandafter\@secondoftwo\fi}

\def\fake@footnotemark{\textsuperscript{\the\numexpr\value{footnote}+1\relax}}
\def\longrightmark{\arrowmeasuring{\fake@footnotemark}{\footnotemark}} % 增加一个判断
\makeatother

然后呢就可以使用

\begin{tabular}{cc}
  a & b \\
  $\xlongrightarrow{x + y \longrightmark}$ & d
\end{tabular}
\footnotetext{note1}

或者

\begin{table}[htbp]
  \begin{tabular}{cc}
    a & b \\
    $\xlongrightarrow{x + y \arrowmeasuring{\csname fake@footnotemark\endcsname}{\tablefootnote{note2}}}$ & d
  \end{tabular}
\end{table}

都能正确生成了。

一个更好的办法是使用 etoolbox 宏包的 \patchcmd 命令,而不直接重定义 \ext@arrow

%\usepackage{etoolbox}
\patchcmd\ext@arrow{\mathop}{\ext@arrow@measuring@true\mathop}{}{}
% 不在 \mathop 之内,必须加上
\patchcmd\ext@arrow{\limits}{\ext@arrow@measuring@false\limits}{}{}

完整的例子:

\documentclass[UTF8,11pt]{ctexart}
\usepackage{hyperref}
\usepackage{extarrows}
\usepackage{tablefootnote}

\usepackage{etoolbox}

\makeatletter
\newif\ifext@arrow@measuring@
\let\saved@ext@arrow\ext@arrow % 保存原始定义
\def\fake@footnotemark{\textsuperscript{\the\numexpr\value{footnote}+1\relax}}
\patchcmd\ext@arrow{\mathop}{\ext@arrow@measuring@true\mathop}{}{}
\patchcmd\ext@arrow{\limits}{\ext@arrow@measuring@false\limits}{}{}
\def\arrowmeasuring#1#2{\ifext@arrow@measuring@#1\else#2\fi}
\def\longrightmark{\arrowmeasuring{\fake@footnotemark}{\footnotemark}}
\def\amsmeasuring#1#2{\ifmeasuring@#1\else#2\fi}
\makeatother

\begin{document}

\begin{tabular}{cc}
  a & b \\
  $\xlongrightarrow{x + y \longrightmark}$ & d
\end{tabular}
\footnotetext{note1}

\begin{table}[htbp]
  \begin{tabular}{cc}
    a & b \\
    $\xlongrightarrow{x + y \arrowmeasuring{\csname fake@footnotemark\endcsname}{\tablefootnote{note2}}}$ & d
  \end{tabular}
\end{table}

\end{document}

image.png

image.png

\ext@arrow 的修改应该是不会影响正常使用的。这对于所有使用 \ext@arrow 定义的命令都是有效的,如 \xrightarrow 等。

另一个方案见:https://tex.stackexchange.com/questions/335968/skipped-footnote-numbers-in-math-mode

不建议在数学模式下使用 footnote

1 个回答

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览