如何在表格中使用缩写

如何在表格中使用缩写

我遇到了一种非常罕见和不常见的情况。我想在表格环境中第一次调用缩写。它按预期工作,但包 hyperref 不喜欢它。以下 MWE 会产生问题:

\documentclass[
   12pt,
   ngerman,
   a4paper,
]{scrreprt}

\usepackage[ngerman]{babel}     
\usepackage[T1]{fontenc}            
\usepackage[utf8]{inputenc} 
\usepackage{lmodern} 

\usepackage{tabularx}                   
\usepackage[]{hyperref}
\usepackage[smaller]{acronym}

\begin{document}

\tableofcontents

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Abkürzungsverzeichnis
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newpage
\addchap{Abkürzungsverzeichnis}
\begin{acronym}[EEPROM] 
   \setlength{\itemsep}{-\parsep}
   % \acro{CV}{Computer Vision}
   \acro{EDR}{Experiment Data Record}
   \acro{RCE}{Rover Compute Element}
   \acro{JPL}{Jet Propulsion Lab}
   \acro{MIPL}{Massive Impulse Propellant Lab}
   \acro{RMC}{Rover Motion Counter}
\end{acronym}

\clearpage

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Kapitel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pagenumbering{arabic} %Arabic numerals

\chapter{TABLE}

Some Text infront of the issuefull table with the abbrevation of \ac{JPL}.

\begin{table}[ht]
   \begin{tabularx}{\textwidth}{|c|l|l|>{\raggedright\arraybackslash}X|}
       \hline
       Pos & Name & Wert & Erklärung \\ \hline
       1 & config & BLUB & \ac{RCE} \\
       2 & prod & BLUB & \ac*{EDR} \\
       3 & site & BLUB & \ac*{RMC} \\
       4 & drive & BLUB & \ac*{RMC} \\
       5 & venue/who & BLUB & \ac{MIPL} (at \ac*{JPL}) or \ac{JPL} \\
       \hline

   \end{tabularx}
\caption{Blub}
\label{tab:Blub}
\end{table}

Now let us call a different Abbrevation from the table, maybe \ac{EDR}.

\end{document}

此 MWE 的警告如下:

There were undefined references.
LaTeX [1, 1]
Hyper reference `acro:EDR' on page 2 undefined.
LaTeX [59, 1]
Hyper reference `acro:EDR' on page 2 undefined.
LaTeX [59, 1]
Hyper reference `acro:RCE' on page 2 undefined.
LaTeX [60, 1]
Hyper reference `acro:RCE' on page 2 undefined.
LaTeX [60, 1]
Hyper reference `acro:MIPL' on page 2 undefined.
LaTeX [62, 1]
Hyper reference `acro:MIPL' on page 2 undefined.
LaTeX [62, 1]

您可能已经意识到,缩写 JPL 不是问题,因为它在表格之前就被调用了,而缩写 RMC 不是问题,因为它被调用时带有星号。因此,用星号调用表格中的所有缩写似乎是一个解决方案。

遗憾的是,我在原始文档中对该解决方案的看法有所不同,并且无法创建有效的 MWE,并出现以下警告:

Label `acro:RMC@cref' multiply defined.
LaTeX [1, 1]
There were multiply-defined labels.
LaTeX [1, 1]

如果在表格内使用两次缩写,或者在表格外再次使用缩写,就会发生这种情况\ac{RMC}

另外,我实际上希望您使用表格内的缩写的简短版本,如果\ac{}我像使用 JPL 一样在表格前调用命令就会发生这种情况。

那么有没有什么方法可以在没有警告的情况下实现这一点,或者我应该重写文本,以便之前正确调用的命令?

答案1

问题不在于表格,而在于tabularx:由于它对其内容进行两次处理,因此首字母缩略词被标记为已使用,然后不会写出标签。

您可以在序言中(tabularx 之后)尝试此操作:

\usepackage{etoolbox}
\makeatletter

\patchcmd \TX@trial
          { \let\hbadness\@tempcnta }
          {\let\AC@placelabel\@gobble\let\hbadness\@tempcnta }{}{\fail}
\makeatother

附言:由于有\pagenumbering{arabic}两个页面编号为 1 且 hyperref 的页面,您不会喜欢这个。

相关内容