Free Software
Recent news (2017-02-08): Added aliases example to the glossaries-extra.sty gallery.

Gallery (glossaries): Adjust alttree Style Sample

Image of
alttree style sample
This example uses the glossaries-extra package, which extends the glossaries package and provides better abbreviation handling.

The initial comment lines below are arara directives. You can remove them if you don't use arara.

% arara: pdflatex
% arara: makeglossaries if found("aux", "@istfilename")
% arara: pdflatex








% setup lengths



          text width=\dimexpr\namewidth-2\nameinnersep-2\nameoutersep,
          inner sep=\nameinnersep,
          outer sep=\nameoutersep
         ] (X) {#2};

 \node[text width=\maxlocwidth,
       rounded corners] 
  (X) {#1};





  \advance\locboxheight by \tmplen
     \advance\tmplen by -\pagetotal
     \advance\tmplen by -\imgheight
     \advance\tmplen by -\locboxheight
  % scope \par change
    (Image file:



\chapter*{Front Matter Test}


\chapter{Main Matter Test}



If you don't use arara, you need to run the following commands:
pdflatex alttree-marginpar
makeglossaries alttree-marginpar
pdflatex alttree-marginpar
These commands can be run from a terminal or command prompt or you might be able to run them by clicking on a button in your text editor.

This is quite a complicated example. It uses the tikz package to add a splash of colour to the name and location list. The location list is formatted according to \GlsXtrFormatLocationList (which takes the location list as the argument). This is redefined so that it typesets the locations in Plum after a curving arrow. This requires locally hiding the hyperlinks so that the link colour doesn't override the text colour:

 {% localise
The default top level indent is suppressed so that the description takes up the text width. This is done by setting \glsxtrtreetopindent to 0pt. The width of the maximum location list is computed and stored in \maxlocwidth and an extra 1em is added to provide a little padding. This is only suitable for short location lists that can fit on a single line. These lengths are all set by \glsxtralttreeInit.

The name is formatted according to \glstreenamebox. This is redefined to protrude out into the left margin and the contents are placed inside a tikz node to give it an Orchid rectangular background. Note that here the new definition of \glstreenamebox ignores its first argument as instead it uses \namewidth to determine its width.

This document uses the dummy entries defined in the sample file example-glossaries-images.tex, which is provided with the glossaries package. These entries have multi-paragraph descriptions, and some of the entries use the user1 key to store the name of an associated image file. These are just the dummy image files provided by the mwe package.

The aim here is to place the location list in the right margin (which can be done with \marginpar) and below that the image (if one has been provided). This can be done with another \marginpar, but this can lead to the image dangling into the footer if there's not enough room for it. The available space needs to be calculated. This depends on \pagegoal, \pagetotal and the height of the image, so the image is first saved in a box and its height is calculated. If there's not enough space, the image is deferred until the next page (using \afterpage provided by the afterpage package). This could still potentially lead to a problem where there's insufficient room for it on the next page, but, in this example, the descriptions are all long enough for this not to be a problem.

Finally, \indexspace is added after the description to provide a little visible separation between each entry, otherwise it looks too cluttered, especially with no paragraph indent at the start of the description. The intergroup space is suppressed using the nogroupskip package option.

Download: PDF, document source.

Last modified: 2017-02-07.

The free resources on this site are funded by book sales, not by adverts. If you would like to help keep this site free of annoying third-party ads, please consider buying a book.

© 2016 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.

Terms of Use Privacy Policy Site Map FAQs