如何制作一个带有分隔的希腊和罗马符号的自定义符号列表?

如何制作一个带有分隔的希腊和罗马符号的自定义符号列表?

我正在使用词汇表包来制作首字母缩略词列表和符号列表(分别)。以下方法,我尝试制作一个具有该布局的符号列表,但其中有单独的希腊和罗马符号部分。

我尝试使用链接的\newglossarystyle命令来执行此操作:

\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {%
     \renewcommand{\arraystretch}{1.5}%
     \begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Symbol & \bfseries \descriptionname & \bfseries Unit & \bfseries First appearance \tabularnewline
    \midrule\endhead}%
    \renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1}  & \glossentrydesc{##1} & \glsentryunit{##1} 
        \tabularnewline
    }%
}

这让我朝着正确的方向前进,罗马字母和希腊字母的分离是正确的。然而,单位列和符号列,除了罗马字母希腊字母指标,完全是空的。 符号词汇表的输出,其中罗马字母和希腊字母分开,但单位和符号缺失或混淆。

摘自问题,在调用之前,我已经unit使用此命令定义了密钥\makeglossaries

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

parent我通过为每个词汇表条目分配一个来区分罗马符号和希腊符号,如下所示这种方法

% Define the parent romand and greek symbols
\newglossaryentry{romanletter}{name={\textbf{Roman letters}}, description={\nopostdesc}, sort={1}, type=symbols}
\newglossaryentry{greekletter}{name={\textbf{Greek letters}}, description={\nopostdesc}, sort={2}, type=symbols}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entries
\newglossaryentry{drag}{name={\ensuremath{D}},
                     sort={drag},
                     description={drag},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{h}{name={\ensuremath{h}},
                     sort={h},
                     description={altitude},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\metre}}}
\newglossaryentry{lift}{name={\ensuremath{L}},
                     sort={lift},
                     description={lift},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{mach}{name={\ensuremath{M}},
                     sort={Mach number},
                     description={Mach number},
                     parent={romanletter},
                     type={symbols},
                     unit={[-]}}
\newglossaryentry{mass}{name={\ensuremath{m}},
                     sort={mass},
                     description={mass},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\kilogram}}}
\newglossaryentry{pitchrate}{name={\ensuremath{q}},
                     sort={q},
                     description={pitch rate},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\radian\per\second}}}
% Some greek letter
\newglossaryentry{eta}{name={\ensuremath{\eta}},
                        sort={7},
                        description={(propulsive) efficiency},
                        parent={greekletter}, 
                        type={symbols},
                        unit={[-]}}

我可能在命令的某个地方出错了\newglossarystyle,但我一直在努力通过阅读来解决这个问题文档并检查了之前发布的问题,但我似乎无法理解。我发现语法\renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1} & \glossentrydesc{##1} & \glsentryunit{##1}相当混乱,无法理解词汇表文档中的所有命令。

在 MWE 中总结以上所有内容:

\documentclass{report}
\usepackage{siunitx} \sisetup{detect-all}
\usepackage{hyperref}
\usepackage[nopostdot, toc, nogroupskip, nomain, indexonlyfirst, acronym, symbols, style=long4col, stylemods={longbooktabs}]{glossaries-extra}
\GlsXtrEnablePreLocationTag{page~}{pages~}

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

\makeglossaries

% Define the parent romand and greek symbols
\newglossaryentry{romanletter}{name={\textbf{Roman letters}}, description={\nopostdesc}, sort={1}, type=symbols}
\newglossaryentry{greekletter}{name={\textbf{Greek letters}}, description={\nopostdesc}, sort={2}, type=symbols}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entries
\newglossaryentry{drag}{name={\ensuremath{D}},
                     sort={drag},
                     description={drag},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{h}{name={\ensuremath{h}},
                     sort={h},
                     description={altitude},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\metre}}}
\newglossaryentry{lift}{name={\ensuremath{L}},
                     sort={lift},
                     description={lift},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\newton}}}
\newglossaryentry{mach}{name={\ensuremath{M}},
                     sort={Mach number},
                     description={Mach number},
                     parent={romanletter},
                     type={symbols},
                     unit={[-]}}
\newglossaryentry{mass}{name={\ensuremath{m}},
                     sort={mass},
                     description={mass},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\kilogram}}}
\newglossaryentry{pitchrate}{name={\ensuremath{q}},
                     sort={q},
                     description={pitch rate},
                     parent={romanletter},
                     type={symbols},
                     unit={\si{\radian\per\second}}}
% Some greek letter
\newglossaryentry{eta}{name={\ensuremath{\eta}},
                        sort={7},
                        description={(propulsive) efficiency},
                        parent={greekletter}, 
                        type={symbols},
                        unit={[-]}}

% Set the new glossary style
\newglossarystyle{symbunitlong}{%
  \setglossarystyle{long4col-booktabs}%
  \renewenvironment{theglossary}%
    {%
     \renewcommand{\arraystretch}{1.5}%
     \begin{longtable}{cp{\glsdescwidth}c>{\centering}p{\glspagelistwidth}}}%
    {\end{longtable}}%
  \renewcommand*{\glossaryheader}{%
    \bfseries Symbol & \bfseries \descriptionname & \bfseries Unit & \bfseries First appearance \tabularnewline
    \midrule\endhead}%
    \renewcommand{\glossentry}[2]{\glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} & \glossentrydesc{##1}  & \glossentrydesc{##1} & \glsentryunit{##1} 
        \tabularnewline
    }%
}

\begin{document}

\glsaddall
\printglossary[type=symbols, style=symbunitlong]

\end{document}

提前致谢!

PS 我还希望每列的宽度能够适应该列中最宽的条目。例如,最后一列应该加宽以显示首次亮相在同一行。此外,条目应该左对齐,而不是居中。不过,这是次要的。

答案1

好吧...我不是词汇表样式方面的专家,所以我尽力了。

首先你最大的错误就是没有充分利用这个glossaries-extra包的功能^_~ 看看这个关联了解更多信息,但请耐心等待,因为您会需要它。除此之外,您还会找到 stylemodlongextralong-loc-sym-desc-name风格。这是您选择风格的完美开端。

通过使用键定义符号,symbol您拥有了样式修改所需的一切。我从原始样式文件中复制了大部分内容(安装包后:MiKTeX->tex->latex->glossaries-extra)。最后但并非最不重要的是定义您的列顺序,当然还有键的使用unit

\documentclass{report}
\usepackage{blindtext}
\usepackage{siunitx}    \sisetup{detect-all}
\usepackage{hyperref}
\usepackage[nopostdot, toc, nogroupskip, nomain, indexonlyfirst, acronym, symbols, style=long4col, stylemods={longextra}]{glossaries-extra}
\GlsXtrEnablePreLocationTag{page~}{pages~}

\glsaddkey
{unit}          % new key
{\relax}        % default value if "unit" isn't used in \newglossaryentry
{\glsentryunit} % analogous to \glsentrytext
{\Glsentryunit} % analogous to \Glsentrytext
{\glsunit}      % analogous to \glstext
{\Glsunit}      % analogous to \Glstext
{\GLSunit}      % analogous to \GLStext

\makeglossaries

% Define the parent roman and greek symbols
\newglossaryentry{romanletter}{
    name={\textbf{Roman letters}},
    description={\nopostdesc}, 
    sort={1}, 
    type=symbols,
}
\newglossaryentry{greekletter}{
    name={\textbf{Greek letters}},
    description={\nopostdesc}, 
    sort={2}, 
    type=symbols,
}

% Don't expand the unit field 
\glssetnoexpandfield{unit}

% Some sample symbol glossary entry with roman letter ...
\newglossaryentry{mass}{
    name={mass},
    symbol={\ensuremath{m}},
    unit={\si{\kilogram}},
    description={mass},
    parent={romanletter},
    type={symbols},
    sort={mass},
}
% ... and also with some greek letter
\newglossaryentry{eta}{
    name={eta},
    symbol={\ensuremath{\eta}},
    unit={[-]},
    description={(propulsive) efficiency},
    parent={greekletter}, 
    type={symbols},
    sort={eta},
}

% Inform glossary about your own key (see manual v1.41, p.60 about its original definition)
\renewcommand{\glslongextraSubNameFmt}[2]{
    \glssubentryitem{#2}\glstarget{#2}{\glsentryunit{#2}\strut}
}
% Set the new glossary style
\newglossarystyle{long-sym-desc-unit-loc}{%
    \setglossarystyle{long-loc-sym-desc-name}%
    \renewenvironment{theglossary}%
    {%
    \glspatchLToutput
    \glslongextraSymLocSetDescWidth
    \edef\@glslongextra@begintab{%
        \noexpand\begin{longtable}{%
                \expandonce\glslongextraSymbolAlign
                \expandonce\glslongextraDescAlign
                \expandonce\glslongextraNameAlign
                \expandonce\glslongextraLocationAlign
        }}%
        \@glslongextra@begintab
    }%
    {\end{longtable}
    }%
    \renewcommand*{\glossaryheader}{%
        \bfseries Symbol%
        & \bfseries \descriptionname %
        & \bfseries Unit %
        & \bfseries \mbox{1st page}%
        \tabularnewline%
        \midrule%
        \endhead%
    }%
    \renewcommand*{\glsgroupheading}[1]{\glslongextraGroupHeading{4}{##1}}%
    \renewcommand{\glossentry}[2]{%
        \glslongextraNameFmt{##1} & & &%
        \tabularnewline
    }% 
    \renewcommand{\subglossentry}[3]{%
        \glslongextraSubSymbolFmt{##1}{##2} &
        \glslongextraSubDescFmt{##1}{##2} &
        \glslongextraSubNameFmt{##1}{##2} &
        \glslongextraSubLocationFmt{##1}{##2}{##3}%
        \tabularnewline
    }%
}

\begin{document}
\blindtext
\gls{eta} 

\Blindtext
\gls{mass}

\printglossary[type=symbols, style=long-sym-desc-unit-loc]
\end{document}

相关内容