Question: I am searching for a way to use X
columns in combination with multipage tables in a custom written glossary style.
Update
According to Nicola Talbot's comment, I have created the following MWEs:
1. old approach using tabu:
\documentclass[a4paper,parskip=half]{scrreprt}
\usepackage{setspace}
\AtBeginDocument{\setstretch{1.25}}
\usepackage{tabu}
\usepackage[xindy, acronyms, nonumberlist, nogroupskip,shortcuts]{glossaries}
\newglossarystyle{customlong}{%
\renewenvironment{theglossary}%
{\tabulinesep=1.2mm \begin{longtabu}{@{}lX}}%
{\end{longtabu}}%
\renewcommand*{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossaryentryfield}[5]{%
\glstarget{##1}{##2} & ##3\glspostdescription\space ##5\\}%
\renewcommand*{\glossarysubentryfield}[6]{%
& \glstarget{##2}{\strut}##4\glspostdescription\space ##6\\}%
\renewcommand*{\glsgroupskip}{ & \\}%
}
\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=customlong]
\acs{DABCO}
\acs{DMSO}
\end{document}
This essentially yields the desired output: The width of the abbreviation column is as expected and the line spacing is not too big.
2. new approach using the alttree style:
\documentclass[a4paper,parskip=half]{scrreprt}
\usepackage{setspace}
\usepackage[xindy, acronyms, nonumberlist, nopostdot, numberline, numberedsection=autolabel, nogroupskip,style=long, shortcuts]{glossaries}
\renewcommand{\glossarypreamble}{\glsfindwidesttoplevelname[\currentglossary]}
\renewcommand*{\glstreenamefmt}[1]{#1}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}}
\AtBeginDocument{\setstretch{1.25}}
\newacronym{DMSO}{DMSO}{dimethyl sulfoxide}
\newacronym{DABCO}{DABCO}{1,4-diazabicyclo[2.2.2]octane}
\begin{document}
\printglossary[type=acronym,style=alttree]
\acs{DABCO}
\acs{DMSO}
\end{document}
This approach yields the desired width of the abbreviation column, however the linepacing in the list ist too big. This distance seems to be effected by parskip=half
and \setstretch{1.25}
but as I need those commands to get the desired line spacing in the rest of the document I don't konw how to get rid of them.
3. new approach using the alttree style, strange spacing:
\documentclass[a4paper,parskip=half]{scrreprt}
\usepackage{setspace}
\usepackage[xindy, acronyms, nonumberlist, nopostdot, numberline, numberedsection=autolabel, nogroupskip,style=long, shortcuts]{glossaries}
\renewcommand{\glossarypreamble}{\glsfindwidesttoplevelname[\currentglossary]}
\renewcommand*{\glstreenamefmt}[1]{#1}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}}
\AtBeginDocument{\setstretch{1.25}}
\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]
\acs{DABCO}
\acs{DMSO}
\end{document}
In this MWE I have included the definition of a long acronym that is not explicitly used in the document itself. However, this long acromym seems to be taken into account while calculating the width of the widest acronym.
Background: I am currently using the glossaries
package to print a list of abbreviations and acronyms. The desired style of the list is a two-colum table with the acronym in the left and the long form or description in the right column. Basically this can be achieved by the acronymstyle long-short
.
The only problem I have when using this style occurs when I have long acronyms in combination with long forms that need a linebreak in the second column. For these cases I have manually been changing \setlength{\glsdescwidth}
to a value that roughly fits the textwidth minus left column width. As the lenght of aconyms keeps changing throughout the writing process I have to keep changing the \setlength{\glsdescwidth}
according to the currently needed width. This is always try and error and not that accurate and therefore quite annoying to me.
I have therefore written a custom style that uses the X
column and the longtabu
environment of the tabu
package to determine the width of the second column automatically:
\newglossarystyle{customlong}{%
\renewenvironment{theglossary}%
{\tabulinesep=1.2mm \begin{longtabu}{@{}lX}}%
{\end{longtabu}}%
\renewcommand*{\glossaryheader}{}%
\renewcommand*{\glsgroupheading}[1]{}%
\renewcommand*{\glossaryentryfield}[5]{%
\glstarget{##1}{##2} & ##3\glspostdescription\space ##5\\}%
\renewcommand*{\glossarysubentryfield}[6]{%
& \glstarget{##2}{\strut}##4\glspostdescription\space ##6\\}%
%\renewcommand*{\glsgroupskip}{ & \\}%
}
\setglossarystyle{customlong}
This has always worked fine for me, but recently I was warned about the usage of the tabu
package due to it being buggy and I myself have encountered some strange beahviour as well (although not with the above described glossarystyle).
I have thus considered switching to the tabularx
package, that offers variable width X
columns as well. But as my list of acronym spreads over more than one page, I need a long table with X
columns.
According to the Overview of packages to create tables there are the ltxtable
and the ltablex
packages to achieve this.
According to the Comparison of ltxtable and ltablex the ltablex
seems to have bugs. Unfortunately, the ltxtable
requires the table to be in a separate file. I am aware of the filecontents
package, but don't konw how to implement it in my case.
alttree
style which can be used as an alternative to the tabular styles?tree
(orindex
) styles, use\renewcommand*{\glstreenamefmt}[1]{#1}
. (If that command's not defined, you have an old version ofglossaries.sty
.) There's a paragraph break between entries. Some of thetree
styles locally alter\parskip
but thealttree
doesn't, so you'd need a MWE to demonstrate it.