![为什么表中的命令不执行?](https://linux22.com/image/480336/%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A1%A8%E4%B8%AD%E7%9A%84%E5%91%BD%E4%BB%A4%E4%B8%8D%E6%89%A7%E8%A1%8C%EF%BC%9F.png)
我认为“etoolbox”包中的命令\apptocmd
在表中不起作用。我应该怎么做?
梅威瑟:
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\mycmd}[1]{%
#1\apptocmd{\saveMyNotes}{#1}{}{}%
}
\newcommand{\saveMyNotes}{}
\begin{document}
\begin{table}
\begin{tabular}{c}
\mycmd{Hi} \\
\mycmd{Hello}
\end{tabular}
\end{table}
\saveMyNotes % <--- This command doesn't execute!!!
\end{document}
答案1
我找到了解决方案。我应该使用\gappto
。
\documentclass{article}
\usepackage{etoolbox}
\newcommand{\mycmd}[1]{%
#1\gappto{\saveMyNotes}{#1}{}{}%
}
\newcommand{\saveMyNotes}{}
\begin{document}
\begin{table}
\begin{tabular}{c}
\mycmd{Hi} \\
\mycmd{Hello}
\end{tabular}
\end{table}
\saveMyNotes % <--- This command doesn't execute!!!
\end{document}