[Tex/LaTex] \usepackage{glossaries} with 3 columns

glossaries

I need to have extra column in the glossary.

My application is list of symbols with

  1. symbol
  2. description
  3. units
\documentclass{article}
\usepackage{glossaries}


\makeglossaries

\newglossaryentry{mwe}{name=MWE, description={Minimum Working Example}}

% the previous line should have some extra field, or i could define my own command.
% Something that would envolve description={ {some text} && {some unit}}

\begin{document}

\printglossaries

\clearpage

This is the call to the \Gls{mwe}

\end{document}

Update: for what it is worth if you are running ubuntu < 12.04, you need to update your packages. (refer to here)

Best Answer

Glossary entries can have up to six user fields. Let's use user1 for units, so the entries will be constructed as

\newglossaryentry{A}{%
name={foo},%
description={bar},%
user1={cm}%
}

Then we need a new style that will make use of the new field. How to define a new style is described in the manual, the important thing to know is that the user fields can be accessed via \glsentryuseri{##1}. To do a style based on longtable, we do (mostly copied from the manual):

\documentclass[a4paper,10pt]{article}
\usepackage{glossaries}
\makeglossaries

\newglossaryentry{A}{%
name={foo},%
description={bar},%
user1={cm}%
}

\newglossaryentry{B}{%
name={AAPL},%
description={apples},%
user1={box}%
}

\newglossaryentry{C}{%
name={BTR},%
description={books to read},%
user1={LoC}%
}

\newglossaryentry{D}{%
name={BTRTIO},%
description={books to read that I own},%
user1={shelf},%
parent={C}
}

\newglossarystyle{aiaostyle}{%
% put the glossary in a longtable environment:
\renewenvironment{theglossary}%
 {\begin{longtable}{lp{\glsdescwidth}cp{\glspagelistwidth}}}%
 {\end{longtable}}%
% Set the table’s header: title row
\renewcommand*{\glossaryheader}{%
 \bfseries Term & \bfseries Description & 
 \bfseries Units & \bfseries Page List
 \\\endhead}%
% No table header:
\renewcommand*{\glossaryheader}{}%
% No heading between groups:
 \renewcommand*{\glsgroupheading}[1]{}%
% Main (level 0) entries displayed in a row optionally numbered:
 \renewcommand*{\glossaryentryfield}[5]{%
    \glstarget{##1}{##2}% Name
    & ##3% Description
    & \glsentryuseri{##1}% Units
    & ##5% Page list
    \\% end of row
 }%
% Similarly for sub-entries (no sub-entry numbers):
\renewcommand*{\glossarysubentryfield}[6]{%
    % ignoring first argument (sub-level)
    \glstarget{##2}{##3}% Name
    & ##4% Description
    & \glsentryuseri{##2}% Units
    & ##6% Page list
    \\% end of row
 }%
% Nothing between groups:
\renewcommand*{\glsgroupskip}{}%
}

\begin{document}
\null
\glsaddall

\glossarystyle{aiaostyle}
\setlength{\glsdescwidth}{0.5\textwidth}
\setlength{\glspagelistwidth}{0.1\textwidth}
\printglossary

\end{document}

The glossary will then be a longtable with four columns, where the third, a c column, will contain the content of the user1 field. glossary with units

Related Question