词汇表:如何在符号列表中添加符号定义/首次出现的页面的列?

词汇表:如何在符号列表中添加符号定义/首次出现的页面的列?

我正在尝试为我的博士论文制作一个符号列表,其中包括一个包含符号单位的列。因此,我使用了以下链接中提供的 latex 代码:词汇表:为单位添加附加列

最小工作示例(MWE):

\documentclass[11pt, pdftex]{scrreprt}

% ---- packages: ---------------
\usepackage[LGR,T1]{fontenc}                
\usepackage[utf8]{inputenc}         
\usepackage[english]{babel}
\usepackage{substitutefont}
\usepackage{newtxtext}                      
\usepackage{newtxmath}                  
\substitutefont{LGR}{\rmdefault}{Tempora}   
\usepackage{siunitx}
\usepackage{amsmath}
\usepackage[pdftex]{hyperref}

\usepackage[            
    nogroupskip,                
    acronym,                
    nomain,                     
    nopostdot,                  
    sort=standard,
    automake,            
    xindy,      
]
{glossaries-extra}

\usepackage{glossary-longbooktabs} 
\setabbreviationstyle[acronym]{long-short}      
\setlength{\glsdescwidth}{18cm} 

% -- new style for list of symbols: ----
\newglossarystyle{symbunitlong}{
    \setglossarystyle{long3col}     % base this style on the list style

    \renewenvironment{theglossary}{ % Change the table type --> 3 columns
        \begin{longtable}{lp{0.5\glsdescwidth}>{\centering\arraybackslash}p{2cm}}}
        {\end{longtable}}

    \renewcommand*{\glossaryheader}{%  Change the table header
        \bfseries Sign  & \bfseries Description     & \bfseries Unit    \\
        \hline 
        \addlinespace[7mm]
        \endhead}

    \renewcommand*{\glossentry}[2]{%  Change the displayed items
        \glstarget{##1}{\glossentryname{##1}} %
        & \glossentrydesc{##1}%     Description
        & \glsunit{##1}  \tabularnewline 
        \addlinespace[2mm]}
} 

% --- define symbollist: ------
\newglossary[slg]{symbolslist}{syi}{syg}{List of Symbols} 

% include third column in list of symbols for units:
\glsaddkey{unit}{\glsentrytext{\glslabel}}{\glsentryunit}{\GLsentryunit}{\glsunit}{\Glsunit}{\GLSunit}

\makeglossaries 
\glssetcategoryattribute{acronym}{glossdesc}{firstuc}

% -------------------------------------------
% define some symbols:
\newglossaryentry{symb:lambda}{
    name={\ensuremath{\lambda}},
    sort={z_lambda},
    description={Thermal conductivity},
    unit={\si{\frac{W}{m \cdot K}}},
    type=symbolslist
}
\newglossaryentry{symb:Pc}{
    name={\ensuremath{P_{\mathrm{C}}}},
    sort={PC},
    description={Carnot power},
    unit={\si{W}},
    type=symbolslist
}           
\newglossaryentry{symb:Qjoule}{
    name={\ensuremath{\dot{Q}_\mathrm{J}}},
    sort={Qjoule},
    description={Joule heating},
    unit={\si{W}},
    type=symbolslist
}   
% -------------------------------------------
% define some abbreviations:
\newacronym{acro:FCL}{FCL}{fault current limiters}
\newacronym{acro:SS}{SS}{stainless steel}
% -------------------------------------------


\begin{document}

\textbf{First page:}    
\begin{itemize}
    \item use of symbols \gls{symb:Qjoule} and \gls{symb:Pc} 
    \item use of abbreviation: \gls{acro:SS}
\end{itemize}
\newpage

\textbf{Second page:}
\begin{itemize}
    \item use of symbol \gls{symb:lambda}
    \item use of abbreviation: \gls{acro:FCL}
\end{itemize}
\newpage

% ---- list of symbols: -------
\printglossary[type=symbolslist, style=symbunitlong]

% ---- list of abbreviations: -------
\printglossary[title={List of Abbreviations}, type=acronym, style=listdotted]

\end{document}  

到目前为止它都有效(参见上面的 MWE),但现在我打算添加第四列,指示符号定义的首次出现/页面。我的符号列表的最终理想状态应如以下屏幕截图所示: 在此处输入图片描述


我只想显示文本中第一次出现相应符号的页码,而不是显示使用该符号的每个页码。但不幸的是,我真的不知道该怎么做,也不知道在我定义的词汇表样式中添加什么。


非常感谢您的帮助!


编辑:

我想知道问题是否不清楚而我无法指出我的问题,或者是否根本不可能实现预期的事情并添加第四列,该列仅指示符号定义的第一次出现/页面。

考虑到与我的问题相关的问题,我认为包选项“indexonlyfirst”可能会有所帮助,但我不知道如何详细地整合它。


编辑: 在此处输入图片描述

答案1

如果您使用symbol密钥而不是为单位提供新密钥,那么altlongragged4col-booktabs风格与您想要的格式非常相似,因此这将是一个更好的起点。

\glsentryunit我精简了您的示例并提供了仅使用该字段的命令等symbol,以防您在文档中需要它们。

\documentclass[11pt]{scrreprt}

\usepackage{siunitx}
\usepackage{hyperref}

\usepackage[            
    nogroupskip,                
    acronym,                
    nomain,                     
    xindy,      
    stylemods={longbooktabs},% patch styles and load glossary-longbooktabs.sty
    indexonlyfirst% only index first use
]
{glossaries-extra}

% prefix page list with "page~" or "pages~"
\GlsXtrEnablePreLocationTag{page~}{pages~}

\setabbreviationstyle[acronym]{long-short}      
\setlength{\glsdescwidth}{8cm} 
\setlength{\glspagelistwidth}{2.5cm} 

% --- define symbollist: ------
\newglossary[slg]{symbolslist}{syi}{syg}{List of Symbols} 

\newcommand{\glsentryunit}{\glsentrysymbol}
\newcommand{\Glsentryunit}{\Glsentrysymbol}
\newcommand{\glsunit}{\glssymbol}
\newcommand{\Glsunit}{\Glssymbol}
\newcommand{\GLSunit}{\GLSsymbol}

\makeglossaries 
\glssetcategoryattribute{acronym}{glossdesc}{firstuc}

% -------------------------------------------
% define some symbols:
\newglossaryentry{symb:lambda}{
    name={\ensuremath{\lambda}},
    sort={z_lambda},
    description={Thermal conductivity},
    symbol={\si{\frac{W}{m \cdot K}}},
    type=symbolslist
}
\newglossaryentry{symb:Pc}{
    name={\ensuremath{P_{\mathrm{C}}}},
    sort={PC},
    description={Carnot power},
    symbol={\si{W}},
    type=symbolslist
}           
\newglossaryentry{symb:Qjoule}{
    name={\ensuremath{\dot{Q}_\mathrm{J}}},
    sort={Qjoule},
    description={Joule heating},
    symbol={\si{W}},
    type=symbolslist
}   
% -------------------------------------------
% define some abbreviations:
\newacronym{acro:FCL}{FCL}{fault current limiters}
\newacronym{acro:SS}{SS}{stainless steel}
% -------------------------------------------


\begin{document}

\textbf{First page:}    
\begin{itemize}
    \item use of symbols \gls{symb:Qjoule} and \gls{symb:Pc} 
    \item use of abbreviation: \gls{acro:SS}
\end{itemize}
\newpage

\textbf{Second page:}
\begin{itemize}
    \item use of symbol \gls{symb:lambda}
    \item use of abbreviation: \gls{acro:FCL}
\end{itemize}
\newpage

\textbf{Third page:}    
\begin{itemize}
    \item another use of symbols \gls{symb:Qjoule} and \gls{symb:Pc} 
    \item another use of abbreviation: \gls{acro:SS}
    \item another use of symbol \gls{symb:lambda}
    \item another use of abbreviation: \gls{acro:FCL}
\end{itemize}
\newpage


% ---- list of symbols: -------
\renewcommand{\entryname}{Sign}
\renewcommand{\symbolname}{Unit}
\renewcommand{\pagelistname}{First appearance\slash definition}
\printglossary[type=symbolslist, style=altlongragged4col-booktabs]

% ---- list of abbreviations: -------
\printglossary[title={List of Abbreviations}, type=acronym, style=listdotted]

\end{document}  

得出的结果为:

符号列表的图像

除列对齐外,几乎匹配。

风格altlong4col-booktabs定义如下:

\newglossarystyle{altlong4col-booktabs}{%
  \glspatchLToutput
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {\begin{longtable}{lp{\glsdescwidth}lp{\glspagelistwidth}}}%
    {\end{longtable}}%
}

这反过来使用long4col-booktabs设置标题:

  \renewcommand*{\glossaryheader}{%
    \toprule \bfseries \entryname &
    \bfseries \descriptionname &
    \bfseries \symbolname &
    \bfseries \pagelistname
    \tabularnewline\midrule\endhead
    \bottomrule\endfoot}%

因此,如果您不想要顶部规则和底部规则,也可以重新定义它们,并且您可能更愿意用硬编码值替换命令\entryname\symbolname\pagelistname不必重新定义它们。

\glspatchLToutput样式中的补丁altlong4col-booktabs是多余的,因为它已经被应用long4col-booktabs,因此可以省略。

以下是结合上述内容的新风格:

\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {\begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Sign &
    \bfseries \descriptionname &
    \bfseries Unit &
    \bfseries First appearance\slash definition
    \tabularnewline\midrule\endhead}%
}

完整的 MWE 为:

\documentclass[11pt]{scrreprt}

\usepackage{siunitx}
\usepackage{hyperref}

\usepackage[            
    nogroupskip,                
    acronym,                
    nomain,                     
    xindy,      
    stylemods={longbooktabs},% patch styles and load glossary-longbooktabs.sty
    indexonlyfirst% only index first use
]
{glossaries-extra}

% prefix page list with "page~" or "pages~"
\GlsXtrEnablePreLocationTag{page~}{pages~}

\setabbreviationstyle[acronym]{long-short}      
\setlength{\glsdescwidth}{8cm} 
\setlength{\glspagelistwidth}{2.5cm} 

% --- define symbollist: ------
\newglossary[slg]{symbolslist}{syi}{syg}{List of Symbols} 

\newcommand{\glsentryunit}{\glsentrysymbol}
\newcommand{\Glsentryunit}{\Glsentrysymbol}
\newcommand{\glsunit}{\glssymbol}
\newcommand{\Glsunit}{\Glssymbol}
\newcommand{\GLSunit}{\GLSsymbol}

\makeglossaries 
\glssetcategoryattribute{acronym}{glossdesc}{firstuc}

\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {\begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Sign &
    \bfseries \descriptionname &
    \bfseries Unit &
    \bfseries First appearance\slash definition
    \tabularnewline\midrule\endhead}%
}

% -------------------------------------------
% define some symbols:
\newglossaryentry{symb:lambda}{
    name={\ensuremath{\lambda}},
    sort={z_lambda},
    description={Thermal conductivity},
    symbol={\si{\frac{W}{m \cdot K}}},
    type=symbolslist
}
\newglossaryentry{symb:Pc}{
    name={\ensuremath{P_{\mathrm{C}}}},
    sort={PC},
    description={Carnot power},
    symbol={\si{W}},
    type=symbolslist
}           
\newglossaryentry{symb:Qjoule}{
    name={\ensuremath{\dot{Q}_\mathrm{J}}},
    sort={Qjoule},
    description={Joule heating},
    symbol={\si{W}},
    type=symbolslist
}   
% -------------------------------------------
% define some abbreviations:
\newacronym{acro:FCL}{FCL}{fault current limiters}
\newacronym{acro:SS}{SS}{stainless steel}
% -------------------------------------------


\begin{document}

\textbf{First page:}    
\begin{itemize}
    \item use of symbols \gls{symb:Qjoule} and \gls{symb:Pc} 
    \item use of abbreviation: \gls{acro:SS}
\end{itemize}
\newpage

\textbf{Second page:}
\begin{itemize}
    \item use of symbol \gls{symb:lambda}
    \item use of abbreviation: \gls{acro:FCL}
\end{itemize}
\newpage

\textbf{Third page:}    
\begin{itemize}
    \item another use of symbols \gls{symb:Qjoule} and \gls{symb:Pc} 
    \item another use of abbreviation: \gls{acro:SS}
    \item another use of symbol \gls{symb:lambda}
    \item another use of abbreviation: \gls{acro:FCL}
\end{itemize}
\newpage


% ---- list of symbols: -------
\printglossary[type=symbolslist, style=symbunitlong]

% ---- list of abbreviations: -------
\printglossary[title={List of Abbreviations}, type=acronym, style=listdotted]

\end{document} 

得出的结果为:

符号列表的图像

增加所有行之间的间隙的最简单方法是更改\arraystretch​​。默认值为 1。下面对样式的修改将其增加到 1.5(更改是局部的,因此不会影响符号列表之后的任何表格)。

\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {%
     \renewcommand{\arraystretch}{1.5}%
     \begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Sign &
    \bfseries \descriptionname &
    \bfseries Unit &
    \bfseries First appearance\slash definition
    \tabularnewline\midrule\endhead}%
}

您可以根据需要调整此值,值越大,行距越大。

相关内容