使用 bib2gls 的首字母缩略词列表对齐错误

使用 bib2gls 的首字母缩略词列表对齐错误

最近我学会了如何使用bib2gls来生成缩写、首字母缩略词、符号等的列表。之前描述了一种强大的方法帖子

但是,当我尝试在我使用的模板中最终实现此方法时,出现了一个错误。

set-widest尽管我在\GlsXtrLoadResourceswith中使用了style=alttree首字母缩略词列表,但仍然有一些首字母缩略词没有正确对齐。这是为什么?我真的不明白。

您可以在附图中看到结果。在此处输入图片描述

在我大学提供的模板中,我正在深入研究设置以查看是否存在错误,但我找不到它。可能存在冲突,但我不知道是什么。我在这里放了main.tex包含设置的文件代码:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Settings
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[a4paper,11pt,fleqn]{book}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french,german,english]{babel}

\usepackage{nameref}% http://ctan.org/pkg/nameref
\usepackage[cbgreek]{textgreek}

% Use of SI units
\usepackage{siunitx}

% For figures
\usepackage{graphicx}
\usepackage{xcolor}
\graphicspath{{images/}}
\usepackage{rotating} % Rotate figures
\usepackage{subfig}
% Caption package to force center of captions
\usepackage[justification=centering]{caption}

% Landscape tables and long tables
\usepackage{booktabs}
\usepackage{lscape}
\usepackage{longtable}

% For the adjustwidth environment
\usepackage{changepage}   

% symbols
\usepackage{textcomp}   % Textregistered and textcopyright
\usepackage{amssymb}

% Label in the figure
\newcommand{\subfigimg}[3][,]{%
  \setbox1=\hbox{\includegraphics[#1]{#3}}% Store image in box
  \leavevmode\rlap{\usebox1}% Print image
  \rlap{\hspace*{11pt}\raisebox{\dimexpr\ht1-1\baselineskip}{#2}}% Print label
  \phantom{\usebox1}% Insert appropriate spcing
}

\usepackage{fourier}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\setlength{\textwidth}{146.8mm} % = 210mm - 37mm - 26.2mm
\setlength{\oddsidemargin}{11.6mm} % 37mm - 1in (from hoffset)
\setlength{\evensidemargin}{0.8mm} % = 26.2mm - 1in (from hoffset)
\setlength{\topmargin}{-2.2mm} % = 0mm -1in + 23.2mm 
\setlength{\textheight}{221.9mm} % = 297mm -29.5mm -31.6mm - 14mm (12 to accomodate footline with pagenumber)
\setlength{\headheight}{14pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% To adujst the titlemargin
\usepackage{scrextend}

\setlength{\parindent}{0pt}

\usepackage{setspace} % increase interline spacing slightly
\setstretch{1.1}

\usepackage{lipsum}
\usepackage{microtype}
\usepackage{url}
\usepackage[final]{pdfpages}


\usepackage{fancyhdr}
\renewcommand{\sectionmark}[1]{\markright{\thesection\ #1}}
\pagestyle{fancy}
    \fancyhf{}
    \renewcommand{\headrulewidth}{0.4pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyhead[OR]{\bfseries \nouppercase{\rightmark}}
    \fancyhead[EL]{\bfseries \nouppercase{\leftmark}}
    \fancyfoot[EL,OR]{\thepage}
\fancypagestyle{plain}{
    \fancyhf{}
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
    \fancyfoot[EL,OR]{\thepage}}
\fancypagestyle{addpagenumbersforpdfimports}{
    \fancyhead{}
    \renewcommand{\headrulewidth}{0pt}
    \fancyfoot{}
    \fancyfoot[RO,LE]{\thepage}
}

\usepackage{listings}
\lstset{language=[LaTeX]Tex,tabsize=4, basicstyle=\scriptsize\ttfamily, showstringspaces=false, numbers=left, numberstyle=\tiny, numbersep=10pt, breaklines=true, breakautoindent=true, breakindent=10pt}


\makeatletter
\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else
    \hbox{}
    \thispagestyle{empty}
    \newpage
    \if@twocolumn\hbox{}\newpage\fi\fi\fi}
\makeatother \clearpage{\pagestyle{plain}\cleardoublepage}


%%%%% CHAPTER HEADER %%%%
\usepackage{color}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\newcommand*\chapterlabel{}
%\renewcommand{\thechapter}{\Roman{chapter}}
\titleformat{\chapter}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
    {\normalfont\bfseries\Huge} % format of the chapter
    {\gdef\chapterlabel{\thechapter\ }}     % the label 
    {0pt} % separation between label and chapter-title
      {\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-8cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=black] (0,0) rectangle(35.5mm,15mm);
        \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum height=30mm,inner sep=0mm] at (current page.north west)
        {\parbox[top][30mm][t]{15mm}{\raggedleft $\phantom{\textrm{l}}$\color{white}\chapterlabel}};  %the black l is just to get better base-line alingement
        \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north west)
              {\parbox[top][30mm][t]{\textwidth}{\color{black}#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
   \gdef\chapterlabel{}
  } % code before the title body

\titlespacing*{\chapter}{0pt}{50pt}{30pt}
\titlespacing*{\section}{0pt}{13.2pt}{*0}  % 13.2pt is line spacing for a text with 11pt font size
\titlespacing*{\subsection}{0pt}{13.2pt}{*0}
\titlespacing*{\subsubsection}{0pt}{13.2pt}{*0}

\newcounter{myparts}
\newcommand*\partlabel{}
\titleformat{\part}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
    {\normalfont\bfseries\Huge} % format of the part
    {\gdef\partlabel{\thepart\ }}     % the label 
    {0pt} % separation between label and part-title
      {\setlength{\unitlength}{20mm}
      \addtocounter{myparts}{1}
      \begin{tikzpicture}[remember picture,overlay]
    \node[anchor=north west,xshift=-65mm,yshift=-6.9cm-\value{myparts}*20mm] at (current page.north east) % for unknown reasons: 3mm missing -> 65 instead of 62
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=black] (0,0) rectangle(62mm,20mm);   % -\value{myparts}\unitlength
        \node[anchor=north west,yshift=-6.1cm-\value{myparts}*20mm,xshift=-60.5mm,minimum height=30mm,inner sep=0mm] at (current page.north east)
        {\parbox[top][30mm][t]{55mm}{\raggedright \color{white}Part \partlabel $\phantom{\textrm{l}}$}};  %the phantom l is just to get better base-line alingement
        \node[anchor=north east,yshift=-6.1cm-\value{myparts}*20mm,xshift=-63.5mm,text width=\textwidth,minimum height=30mm,inner sep=0mm] at (current page.north east)
              {\parbox[top][30mm][t]{\textwidth}{\raggedleft \color{black}#1}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
   \gdef\partlabel{}
  } % code before the title body



\usepackage{hyperref} % les entrées de la table des matières deviennent des liens internes au sein du pdf.
\hypersetup{pdfborder={0 0 0},
    colorlinks=true,
    linkcolor=black,
    citecolor=black,
    urlcolor=black}
\urlstyle{same}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Glossary
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[record,abbreviations,acronyms,symbols,%
stylemods={tree},style=treegroup]{glossaries-extra}

% always set the abbreviation style before \GlsXtrLoadResources
\setabbreviationstyle{short-long-desc}
\setabbreviationstyle[acronym]{short-long}


% Assign group titles:
\glsxtrsetgrouptitle{latin}{Latin Symbols}
\glsxtrsetgrouptitle{greek}{Greek Symbols}

\GlsXtrLoadResources[
  src={no-interpret-preamble,acronym},% bib files
  sort={en-US},% sort according to this locale
  set-widest,% needed for 'alttree' styles
%  save-locations=false % use this command to pring only the acronyms you are using
  selection=all,% select all entries in the .bib files
  save-locations=false % do not save locations
]


\GlsXtrLoadResources[
 src={symbols-greek},
 sort={letter-case},% sort according Unicode value
 symbol-sort-fallback=name,
 type=symbols,
 group=greek,
 set-widest,% needed for 'alttree' styles
 save-locations=false % do not save locations
]

\GlsXtrLoadResources[
 src={symbols-latin},
  sort={letter-case},% sort according Unicode value
  symbol-sort-fallback=name,
  type=symbols,
  group=latin,
  set-widest,% needed for 'alttree' styles
  save-locations=false % do not save locations
]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Document
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
\frontmatter % Partie préface du document

% List of acronyms
\printunsrtglossary[type=acronym,style=alttree,title={List of Acronyms}]
%List of symbols
\printunsrtglossary[type=symbols,style=alttreegroup,title={List of Symbols}]



% space before each new paragraph according to the template guidelines.
%(needs to be after titlepage and frontmatter to keep the table of contents lists short)
\setlength{\parskip}{1em}


\mainmatter % Corps du document

Some useful example of acronyms used for the fist time: \gls{bse}, \gls{dbtt}, \gls{hd} or \gls{wd}.

And some useful example of acronyms used for the second time: \gls{bse}, \gls{dbtt}, \gls{hd} or \gls{wd}.

Some example of greek symbols: \gls{delta}, \gls{alpha} and \gls{alphalin}.

Some example of latin symbols: \gls{a}, \gls{v} and \gls{F}.

\end{document}

还有其他文件。第一个文件定义首字母缩略词。该acronym.bib文件也应与主文件放在同一文件夹中:

% acronym.bib

% This file is public domain. See the "Examples" chapter
% in the bib2gls user manual for a more detailed description
% of this file.

% Encoding: UTF-8


@acronym{bse,
  short={BSE},
  long={Backscattered Electrons},
  identifier={acronym}
}

@acronym{dbtt,
  short={DBTT},
  long={Ductile-Brittle Transition Temperature},
  identifier={acronym}
}

@acronym{hd,
  short={HD},
  long={High Definition},
  identifier={acronym}
}

@acronym{wd,
  short={WD},
  long={Working Distance},
  identifier={acronym}
}

然后是两个符号列表。根据文件,第一个是希腊符号symbols-greek.bib

% symbols-greek.bib

% Put here all greek symbols
% Encoding: UTF-8

@symbol{alpha,
 name={\ensuremath{\alpha}},
 description={angular acceleration},
 indentifier={mathgreek}
}
@symbol{alphalin,
 name={\ensuremath{\alpha_{L}}},
 description={linear coefficient of thermal expansion},
 indentifier={mathgreek}
}
@symbol{delta,
 name={\ensuremath{\delta}},
 description={Kronecker delta},
 indentifier={mathgreek}
}
@symbol{lambda,
 name={\ensuremath{\lambda}},
 description={Lagrange multiplier},
 indentifier={mathgreek}
}
@symbol{chi,
 name={\ensuremath{\chi}},
 description={chromatic number},
 indentifier={mathgreek}
}
@symbol{rho,
 name={\ensuremath{\rho}},
 description={density},
 indentifier={mathgreek}
}
@symbol{zeta,
 name={\ensuremath{\zeta}},
 description={Riemann zeta function},
 indentifier={mathgreek}
}

拉丁符号列表如下(symbols-latin.bib):

% symbols-latin.bib

% Put here all latin symbols
% Encoding: UTF-8

@symbol{x,
 name={\ensuremath{x}},
 description={position},
 indentifier={mathlatin}
}
@symbol{v,
 name={\ensuremath{v}},
 description={velocity},
 indentifier={mathlatin}
}
@symbol{a,
 name={\ensuremath{a}},
 description={acceleration},
 indentifier={mathlatin}
}
@symbol{t,
 name={\ensuremath{t}},
 description={time},
 indentifier={mathlatin}
}
@symbol{E,
 name={\ensuremath{E}},
 description={Young's modulus},
 indentifier={mathlatin}
}
@symbol{F,
 name={\ensuremath{F}},
 description={force},
 indentifier={mathlatin}
}
@symbol{Tm,
 name={\ensuremath{T_{m}}},
 description={melting point temperature},
 indentifier={mathlatin}
}
@symbol{KIC,
 name={\ensuremath{K_{IC}}},
 description={stress intensity factor},
 indentifier={mathlatin}
}
@symbol{Z,
 name={\ensuremath{Z}},
 description={atomic number},
 indentifier={mathlatin}
}

最后,no-interpret-preamble.bib文件:

% This file is public domain. See the "Examples" chapter
% in the bib2gls user manual for a more detailed description
% of this file.

% Encoding: UTF-8

@preamble{"\providecommand{\sortname}[2]{#1 #2}
\providecommand{\sortvonname}[3]{#1 #2 #3}
\providecommand{\sortart}[2]{#1 #2}
\providecommand{\sortmediacreator}[2]{#1 #2}"}

有人能帮我吗?我会非常感激的。

答案1

set-widest查找最宽的名称(bib2gls 文档,第 86 页)。但是,首字母缩略词没有名称字段。一种解决方案是通过添加replicate-fields={short=name}\GlsXtrLoadResources[…]添加首字母缩略词的字段将短字段复制到名称字段。因此,它将显示:

\GlsXtrLoadResources[
  src={no-interpret-preamble,acronym},% bib files
  sort={en-US},% sort according to this locale
  set-widest,% needed for 'alttree' styles
%  save-locations=false % use this command to pring only the acronyms you are using
  selection=all,% select all entries in the .bib files
  save-locations=false, % do not save locations
  replicate-fields={short=name}
]

set-widest寻找最长的名称字段是添加@entry产生您在自己的答案中显示的结果的原因,@entry具有名称字段。set-widest占用名称的宽度@entry。 这也解释了为什么添加@entry markdown产生与添加不同的对齐方式LaTeXmarkdown比长LaTeX。 换句话说,对齐不取决于@entrybib文件中的数量,而是取决于其名称的长度。

答案2

通过比较有效的代码,我发现如果我添加以下代码

@preamble{"\providecommand{\abbrvtag}[1]{#1}"}
@string{markuplang="\abbrvtag{m}arkup \abbrvtag{l}anguage"}

@entry{TeX,
  name={{}\TeX},
  description={a format for describing complex type and page layout
    often used for mathematics, technical, and academic publications},
  identifier={markuplanguage}
}

@entry{LaTeX,
  name={{}\LaTeX},
  description={a format of \glstext{TeX} designed to separate
   content from style},
  identifier={markuplanguage}
}

@entry{markdown,
  name={markdown},
  description={a lightweight markup language with plain text
    formatting syntax},
  identifier={markuplanguage}
}

在文件开头acronym.bib,那么我得到了正确的对齐。在下图中检查结果。

在此处输入图片描述

该文件acronym.bib变为:

% acronym.bib

% This file is public domain. See the "Examples" chapter
% in the bib2gls user manual for a more detailed description
% of this file.

% Encoding: UTF-8

@preamble{"\providecommand{\abbrvtag}[1]{#1}"}
@string{markuplang="\abbrvtag{m}arkup \abbrvtag{l}anguage"}

@entry{TeX,
  name={{}\TeX},
  description={a format for describing complex type and page layout
    often used for mathematics, technical, and academic publications},
  identifier={markuplanguage}
}

@entry{LaTeX,
  name={{}\LaTeX},
  description={a format of \glstext{TeX} designed to separate
   content from style},
  identifier={markuplanguage}
}

@entry{markdown,
  name={markdown},
  description={a lightweight markup language with plain text
    formatting syntax},
  identifier={markuplanguage}
}

@acronym{bse,
  short={BSE},
  long={Backscattered Electrons},
  identifier={acronym}
}

@acronym{dbtt,
  short={DBTT},
  long={Ductile-Brittle Transition Temperature},
  identifier={acronym}
}

@acronym{hd,
  short={HD},
  long={High Definition},
  identifier={acronym}
}

@acronym{wd,
  short={WD},
  long={Working Distance},
  identifier={acronym}
}

就像对齐取决于@entry您在文档开头放置的 的数量。在本例中,我有三个@entry。例如,如果您删除该markdown条目,则剩下两个@entry,结果变为

在此处输入图片描述

我不知道我们为什么会有这种行为。它不遵循任何逻辑。也许这表明我们有一个美丽的虫子???:-)

相关内容