带有词汇表的组/父标题周围的垂直间距

带有词汇表的组/父标题周围的垂直间距

我正在使用书籍课程撰写论文,借助词汇表包,我可以获得按样式分组的不同类别的符号列表alttree

由于我使用的是“选项 2”,即使用makeindex\makeglossaries因此\printglossaries我不得不使用 创建不同的类别(这里是希腊文和拉丁文) \newglossaryentry。我通过自己对条目进行排序并使用sort=def,nogroupskip包选项来避免奇怪的垂直间距。

然而,我对“角频率”和标题“拉丁符号”之间的空间(图片上为红色)以及标题和其第一个条目之间的一小部分空间(蓝色)不满意

有没有一种优雅的方法可以为这两个位置添加更多的垂直空间,而无需更改条目之间的垂直空间?我尝试查看手册和包代码,它们都很冗长,但与其他方法相比,词汇表的定制极其痛苦。

标题附近的垂直间距太小

梅威瑟:

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,nonumberlist,sort=def,nogroupskip]{glossaries}

\newglossary*{symbols}{List of Symbols}
\makeglossaries

\glssetwidest{X}

\newglossaryentry{greeksymbols} {name={Greek symbols}, description={\nopostdesc}}
\newglossaryentry{latinsymbols} {name={Latin symbols}, description={\nopostdesc}}

\newglossaryentry{s_tau}  {type=symbols, parent=greeksymbols, description={relaxation time},   name={\ensuremath{\tau}}}
\newglossaryentry{s_omega}{type=symbols, parent=greeksymbols, description={angular frequency}, name={\ensuremath{\omega}}}

\newglossaryentry{s_A}    {type=symbols, parent=latinsymbols, description={wave amplitude},    name={\ensuremath{A}}}
\newglossaryentry{s_F}    {type=symbols, parent=latinsymbols, description={reduced frequency}, name={\ensuremath{F}}}

\begin{document}

\printglossary[type=symbols,style=alttree]

\clearpage

Hello world, using \gls{s_tau}, \gls{s_omega}, \gls{s_A} and \gls{s_F}

\end{document}

答案1

由于我遇到了类似的问题,所以我想要一个更好的通用解决方案。使用此解决方案,您可以根据每个条目的层在条目前后设置任意垂直空间。

改编

  • 我创造了一种新风格:glossary-alttreeX.sty
    • 它包含样式的扩展alttree
    • 它提供了设置每层垂直空间的命令:
      \alttreeXsetLayerVS[<layer>]{<vertical space before>}{<vertical space after}
      
      • 默认图层为0(第一层)
  • 使用样式并设置间距:
    \usepackage{glossary-alttreeX}
    \alttreeXsetLayerVS{2ex}{.2ex} % sets vs for layer 0
    \alttreeXsetLayerVS[1]{.8ex}{.2ex}
    
  • 用于\glsaddallunused打印所有词汇表条目,而不必列出它们并设置style=alttreeX
    \glsaddallunused
    \printglossary[type=symbols,style=alttreeX]
    

结果

在此处输入图片描述

笔记

将其glossary-alttreeX.sty放入与 tex 文件相同的目录或本地目录中(参见包 - 我应该将自己的 .sty 或 .cls 文件放在哪里,以使它们可供我的所有 .tex 文件使用?)。

代码

glossary-alttreeX.sty

% This is file `glossary-alttreeX.sty' by dexteritas (Copyright 2022)
% This file is based on `glossary-tree.sty' by Nicola Talbot (Copyright 2021)
\ProvidesPackage{glossary-alttreeX}[2022/09/02]

\providecommand{\alttreeXsetLayerVS}[3][0]{%
    % [#1] = Layer
    %  #2  = vertical space before
    %  #3  = vertical space after
    \@namedef{@alttreeXvsLayer#1-Before}{#2}
    \@namedef{@alttreeXvsLayer#1-After}{#3}
}

\newglossarystyle{alttreeX}{%
  \renewenvironment{theglossary}%
    {\def\@gls@prevlevel{-1}%
     \mbox{}\par}%
    {\par}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand{\glossentry}[2]{%
    \ifnum\@gls@prevlevel=0\relax
    \else
       \settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
    \fi
    \hangindent\glstreeindent
    \parindent\glstreeindent
    \ifcsname @alttreeXvsLayer0-Before\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer0-Before}} % NEW
    \fi                                            % NEW
    \makebox[0pt][r]{\glstreenamebox{\glstreeindent}{%
       \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
    \ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
    \glossentrydesc{##1}\glspostdescription \space ##2\par
    \ifcsname @alttreeXvsLayer0-After\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer0-After}} % NEW
    \fi                                           % NEW
    \def\@gls@prevlevel{0}%
  }%
  \renewcommand{\subglossentry}[3]{%
    \ifnum##1=1\relax
      \glssubentryitem{##2}%
    \fi
    \ifnum\@gls@prevlevel=##1\relax
    \else
      \@ifundefined{@glswidestname\romannumeral##1}{%
        \settowidth{\gls@tmplen}{\glstreenamefmt{\@glswidestname\space}}}{%
        \settowidth{\gls@tmplen}{\glstreenamefmt{%
           \csname @glswidestname\romannumeral##1\endcsname\space}}}%
      \ifnum\@gls@prevlevel<##1\relax
         \setlength\glstreeindent\gls@tmplen
         \addtolength\glstreeindent\parindent
         \parindent\glstreeindent
      \else
         \@ifundefined{@glswidestname\romannumeral\@gls@prevlevel}{%
           \settowidth{\glstreeindent}{\glstreenamefmt{%
              \@glswidestname\space}}}{%
           \settowidth{\glstreeindent}{\glstreenamefmt{%
              \csname @glswidestname\romannumeral\@gls@prevlevel
                 \endcsname\space}}}%
         \addtolength\parindent{-\glstreeindent}%
         \setlength\glstreeindent\parindent
      \fi
    \fi
    \hangindent\glstreeindent
    \ifcsname @alttreeXvsLayer##1-Before\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer##1-Before}} % NEW
    \fi                                              % NEW
    \makebox[0pt][r]{\glstreenamebox{\gls@tmplen}{%
      \glstreenamefmt{\glstarget{##2}{\glossentryname{##2}}}}}%
    \ifglshassymbol{##2}{(\glossentrysymbol{##2})\space}{}%
    \glossentrydesc{##2}\glspostdescription\space ##3\par
    \ifcsname @alttreeXvsLayer##1-After\endcsname   % NEW
      \vspace{\@nameuse{@alttreeXvsLayer##1-After}} % NEW
    \fi                                             % NEW
    \def\@gls@prevlevel{##1}%
  }%
  \renewcommand*{\glsgroupskip}{\ifglsnogroupskip\else\indexspace\fi}%
}

\endinput

example.tex

\documentclass[a4paper,12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[automake,nonumberlist,sort=def,nogroupskip]{glossaries}

\usepackage{glossary-alttreeX}
\alttreeXsetLayerVS{2ex}{.2ex}
\alttreeXsetLayerVS[1]{.8ex}{.2ex}

\newglossary*{symbols}{List of Symbols}
\makeglossaries

\glssetwidest{X}

\newglossaryentry{A} {name={Topic A}, description={\nopostdesc}}
\newglossaryentry{B} {name={Topic B}, description={\nopostdesc}}

\newglossaryentry{greeksymbols} {name={Greek symbols}, description={\nopostdesc}, parent=A}
\newglossaryentry{latinsymbols} {name={Latin symbols}, description={\nopostdesc}, parent=A}

\newglossaryentry{s_tau}  {type=symbols, parent=greeksymbols, description={relaxation time},   name={\ensuremath{\tau}}}
\newglossaryentry{s_omega}{type=symbols, parent=greeksymbols, description={angular frequency}, name={\ensuremath{\omega}}}

\newglossaryentry{s_A}    {type=symbols, parent=latinsymbols, description={wave amplitude},    name={\ensuremath{A}}}
\newglossaryentry{s_F}    {type=symbols, parent=latinsymbols, description={reduced frequency}, name={\ensuremath{F}}}

\newglossaryentry{greeksymbolsB} {name={Greek symbols}, description={\nopostdesc}, parent=B}

\newglossaryentry{s_tauB}  {type=symbols, parent=greeksymbolsB, description={relaxation time},   name={\ensuremath{\tau}}}

\begin{document}

\glsaddallunused
\printglossary[type=symbols,style=alttreeX]

\end{document}

相关内容