标题基本上是这么说的:当我第一次在文档中调用首字母缩略词时,而这恰好是在 tabu/longtabu 环境中,首字母缩略词不会展开。有什么想法可以解决这个问题吗?
以下是 MWE:
\documentclass[]{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[]{acronym}
\begin{document}
\acrodef{EIA}[EIA]{United States Energy Information Administration}
\begin{longtabu} to 0.9\linewidth{lX}
\toprule
\textbf{Some header} & \\
\midrule
\endfirsthead\\
\toprule
\textbf{Some header} \\
\midrule
\endhead
\bottomrule\\
\endfoot
\bottomrule
\endlastfoot
\ac{EIA} \\
\end{longtabu}
\acresetall
\begin{table}[htbp]
\begin{tabu} to 0.9\linewidth{lX}
\toprule
\ac{EIA} \\
\bottomrule
\end{tabu}
\end{table}
\end{document}
答案1
tabu
的表格需要在排版之前测量表格内容。在此过程中,缩写词已被使用。如果这是缩写词的第一次使用,那么它永远不会被打印,因为从排版阶段的角度来看,缩写词已经被使用过(即在测量阶段)。
但是,针对这种情况,提供了在测量阶段添加的tabu
命令。在我们的例子中,我们需要暂时重新定义(的内部版本),以便在测量阶段第一次使用时重置首字母缩略词:\tabuDisableCommands{<code>}
<code>
\@ac
\ac
\makeatletter
\tabuDisableCommands{
\renewcommand{\@ac}[1]{%
\ifAC@dua
\ifAC@starred\acl*{#1}\else\acl{#1}\fi
\else
\expandafter\ifx\csname AC@#1\endcsname\AC@used
\ifAC@starred\acs*{#1}\else\acs{#1}\fi
\else
\ifAC@starred\acf*{#1}\else\acf{#1}\fi
\AC@reset{#1}% <<< this is added to the original definition
\fi
\fi
}
}
\makeatother
完整示例:
\documentclass[]{article}
\usepackage{booktabs}
\usepackage{tabu}
\usepackage{longtable}
\usepackage[]{acronym}
\acrodef{EIA}[EIA]{United States Energy Information Administration}
\makeatletter
\tabuDisableCommands{
\renewcommand{\@ac}[1]{%
\ifAC@dua
\ifAC@starred\acl*{#1}\else\acl{#1}\fi
\else
\expandafter\ifx\csname AC@#1\endcsname\AC@used
\ifAC@starred\acs*{#1}\else\acs{#1}\fi
\else
\ifAC@starred\acf*{#1}\else\acf{#1}\fi
\AC@reset{#1}% <<< this is added to the original definition
\fi
\fi
}
}
\makeatother
\begin{document}
\begin{longtabu} to 0.9\linewidth{lX}
\toprule
\textbf{Some header} & \\
\midrule
\endfirsthead\\
\toprule
\textbf{Some header} \\
\midrule
\endhead
\bottomrule\\
\endfoot
\bottomrule
\endlastfoot
\ac{EIA} \\
\ac{EIA} \\
\end{longtabu}
\acresetall
\begin{table}[htbp]
\begin{tabu} to 0.9\linewidth{lX}
\toprule
\ac{EIA} \\
\ac{EIA} \\
\bottomrule
\end{tabu}
\end{table}
\end{document}