Long table with X column for usage with glossaries
As you've noticed \glsfindwidesttoplevelname
checks all defined entries rather than only those that have been used. The glossaries-extra-stylemods
package (loaded with \usepackage[stylemods]{glossaries-extra}
) provides \glsFindWidestUsedTopLevelName
which only checks entries that have been marked as used.
This is useful if your glossary is in the back matter. If your glossary is in the front matter (as in your MWE) then the widest used entry must be calculated at the end of the document and saved in the .aux
file for the next LaTeX run.
\makeatletter
\AtEndDocument{\glsFindWidestUsedTopLevelName[\acronymtype]%
\protected@write\@auxout{}{\string\xglssetwidest{\glsgetwidestname}}%
}
\makeatother
The only problem here is that \acs
doesn't mark the entry as used, so you'll need at least one \ac
(or \gls
etc) for each entry referenced in the document for this to work. If you don't want any of the abbreviations to show the full form use the short-nolong
abbreviation style.
\setabbreviationstyle[acronym]{short-nolong}% glossaries-extra.sty
\newacronym{DMSO}{DMSO}{dimethyl sulfoxide}
\newacronym{DABCO}{DABCO}{1,4-diazabicyclo[2.2.2]octane}
\newacronym{longacronym}{longacronym}{description of a long acronym}
If you want some abbreviations to show the full form on first use then use \newabbreviation
instead of \newacronym
for those abbreviations:
\setabbreviationstyle[acronym]{short-nolong}
\setabbreviationstyle{long-short}
% short-nolong abbreviations:
\newacronym{DMSO}{DMSO}{dimethyl sulfoxide}
\newacronym{DABCO}{DABCO}{1,4-diazabicyclo[2.2.2]octane}
% long-short abbreviations:
\newabbreviation{longacronym}{longacronym}{description of a long acronym}
(These abbreviation styles are actually the default settings for glossaries-extra
. You'll need to change the acronyms
package option to abbreviations
if you want this mixture.)
If you really don't want to use \ac
(or \gls
) then you have to determine which entries have been indexed (rather than being marked as used). This requires either hooking into the indexing mechanism or hooking into the glossary style, both of which still require saving information to the .aux
file for the next run.
(Note that longtable
also requires saving information to the .aux
file to determine the correct column widths for specifiers like l
. The contents of each cell needs to be measured to determine the appropriate width for the given column.)
The extra spacing between entries can be dealt with by locally switching off KOMA's parskip
option which can be done in \glossarypreamble
.
Amended MWE:
\documentclass[a4paper,parskip=half]{scrreprt}
\usepackage{setspace}
\usepackage[xindy,
acronyms,% use 'abbreviations' instead for mixture of `\newacronym` and `\newabbreviation`
nonumberlist,
%nopostdot, % 'nopostdot' is the default with glossaries-extra.sty
numberline,
numberedsection=autolabel,
nogroupskip,
stylemods% load glossaries-extra-stylemods.sty
]{glossaries-extra}
\GlsXtrDefineAcShortcuts % provide \ac etc shortcut commands
\renewcommand{\glossarypreamble}{\KOMAoptions{parskip=off}}
\renewcommand*{\glstreenamefmt}[1]{#1}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}}
\AtBeginDocument{\setstretch{1.25}}
\makeatletter
\AtEndDocument{\glsFindWidestUsedTopLevelName%
\protected@write\@auxout{}{\string\xglssetwidest{\glsgetwidestname}}%
}
\makeatother
\makeglossaries
\setabbreviationstyle[acronym]{short-nolong}
\newacronym{DMSO}{DMSO}{dimethyl sulfoxide}
\newacronym{DABCO}{DABCO}{1,4-diazabicyclo[2.2.2]octane}
\newacronym{longacronym}{longacronym}{description of a long acronym}
\begin{document}
\printglossary[type=acronym,style=alttree]
\ac{DABCO}
\ac{DMSO}
\end{document}