名称字段中术语表和术语表换行符

名称字段中术语表和术语表换行符

我正在使用词汇表包为我的文档生成命名法。问题是我的某些条目在名称字段中有非常长的函数。如何在所需位置添加手动换行符?例如,在第二个条目的函数中的第一个或第二个逗号之后。我不想更改定义,\glssetwidest因为宽度适合大多数条目。

梅威瑟:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
  name = $\omega_i$ ,
  description = Description
}

\newglossaryentry{second_entry}{
  name = {$f(epq_{i}, tlz_{i+1}, xy)$} ,
  description = Description
}


\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree, title=Nomenclature]

\end{document}

编辑: 如果描述很长(例如三行)并且符号跨越两行,则描述中会有一行空白。我该如何更改此行为?

编辑的MWE:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
  name = $\omega_i$ ,
  description = Description
}

\newglossaryentry{second_entry}{
  name = {$f(epq_{i}, tlz_{i+1},\newline xy)$},
  text = {$f(epq_{i}, tlz_{i+1}, xy)$},
  description = {Very long description lines with span several lines and gets broken by a blank line if the symbol span two line. Very long description lines with span several lines and gets broken by a blank line if the symbol span two line.}
}

\makeatletter
\newglossarystyle{alttree2}{%
 \setglossarystyle{alttree}%
  \renewcommand{\glossentry}[2]{%
    \ifnum\@gls@prevlevel=0\relax
    \else
       \settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
    \fi
      \hangindent\glstreeindent
      \parindent\glstreeindent
    \makebox[0pt][r]{\parbox[t]{\glstreeindent}{\raggedright
       \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
    \ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
    \glossentrydesc{##1}\glspostdescription \space ##2\par
    \def\@gls@prevlevel{0}%
  }%
}
\makeatother

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree2, title=Nomenclature]

\end{document}

答案1

alttree使用的样式不允许\makebox换行。您可以基于alttree使用 的样式创建新的样式\parbox。例如:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
  name = $\omega_i$ ,
  description = Description
}

\newglossaryentry{second_entry}{
  name = {$f(epq_{i}, tlz_{i+1},\newline xy)$},
  text = {$f(epq_{i}, tlz_{i+1}, xy)$},
  description = {Description}
}

\makeatletter
\newglossarystyle{alttree2}{%
 \setglossarystyle{alttree}%
  \renewcommand{\glossentry}[2]{%
    \ifnum\@gls@prevlevel=0\relax
    \else
       \settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
    \fi
      \hangindent\glstreeindent
      \parindent\glstreeindent
    \makebox[0pt][r]{\parbox[t]{\glstreeindent}{\raggedright
       \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}%
    \ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
    \glossentrydesc{##1}\glspostdescription \space ##2\par
    \def\@gls@prevlevel{0}%
  }%
}
\makeatother

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree2, title=Nomenclature]

\end{document}

得出的结果为:

在此处输入图片描述

编辑:

\parbox高度会影响描述的第一行,我忘记了这一点。可以使用\smash以下方法消除此问题:

\newglossarystyle{alttree2}{%
 \setglossarystyle{alttree}%
  \renewcommand{\glossentry}[2]{%
    \ifnum\@gls@prevlevel=0\relax
    \else
       \settowidth{\glstreeindent}{\glstreenamefmt{\@glswidestname\space}}%
    \fi
      \hangindent\glstreeindent
      \parindent\glstreeindent
    \makebox[0pt][r]{\smash{\parbox[t]{\glstreeindent}{\raggedright
       \glsentryitem{##1}\glstreenamefmt{\glstarget{##1}{\glossentryname{##1}}}}}}%
    \ifglshassymbol{##1}{(\glossentrysymbol{##1})\space}{}%
    \glossentrydesc{##1}\glspostdescription \space ##2\par
    \def\@gls@prevlevel{0}%
  }%
}

对上述 MWE 的修改现在产生:

词汇表图片

但是,由于这会删除\parbox的高度,如果描述的行数少于名称的行数,则可能会导致多余的行与下一个条目发生冲突。如果这种情况可能发生,最好使用类似表格的样式。您可能需要考虑的另一种可能性是允许长名称溢出并在下一行开始描述,如下所示:

\documentclass[12pt,a4paper]{report}

\usepackage{amsmath}
\usepackage{longtable}
\usepackage[acronym,toc,nopostdot]{glossaries}

\glssetwidest[0]{...................}

\newglossaryentry{first_entry}{
  name = $\omega_i$ ,
  description = Description
}

\newglossaryentry{second_entry}{
  name = {$f(epq_{i}, tlz_{i+1}, xy)$},
  description = {\newline Very long description lines with span several lines and gets broken by a blank line if the symbol span two line. Very long description lines with span several lines and gets broken by a blank line if the symbol span two line.}
}

\makeglossaries

\begin{document}
\glsaddall

\printglossary[nonumberlist, style = alttree, title=Nomenclature]

\end{document}

得出的结果为:

词汇表图片

相关内容