5

I'm trying to make a list with nomenclature using the nomencl package. I have been looking for solutions about what I want, but I've not been lucky so far (and I'm not an expert in these matters).

I want 3 categories (Units, Prefixes and Acronyms), but I would want them to split in columns separately. For example, 2 columns for Units, 3 for Prexies and 1 for Acronyms.

I would also want to centering the labels, but remain the Name/Description/Units left aligned. I've found solutions like

\renewcommand{\nomlabel}[1]{\hfil #1\hfil}

But it also change the subgroup/category name (i.e. Units/Prefixes/Acronyms) alignment and I want them to be left aligned.

Also, in the last group (Acronyms) if one of them is too long, it messes up with the alignment. The solution I've found is changing the label width for a bigger one:

\nomlabelwidth=30mm 

But this also change the label size for the two previous categories and make the document to look gross (like an unnecessary waste of space).

This is the best I've got so far:

\documentclass{article}

\usepackage{amsmath}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[acronym]{glossaries}
\usepackage[utf8]{inputenc}
\usepackage[norefpage]{nomencl}
\usepackage{xstring}

\begin{document}

Some text to compile.

\makenomenclature

%Categories
\renewcommand\nomgroup[1]{%
  \item[\bfseries
  \ifstrequal{#1}{A}{Units}{%
  \ifstrequal{#1}{B}{Prefixes}{%
  \ifstrequal{#1}{C}{Acronyms}}}%
]}

%Add units
\newcommand{\nomunit}[1]{%
  \renewcommand{\nomentryend}{\hspace*{\fill}\makebox[1cm][l]{#1}}%
  }

%Label width
\nomlabelwidth=10mm 

%Units
\nomenclature[A]{Bq}{Becquerel \nomunit{1 des/s}}
\nomenclature[A]{Ci}{Curie \nomunit{$3.7 \times 10^{10} Bq$}}
\nomenclature[A]{N}{Newton \nomunit{$kg m/s^2$}}
\nomenclature[A]{A}{Ampere \nomunit{c/s}}
%Prefixes
\nomenclature[B,01]{f}{femto \nomunit{$10^{-15}$}}
\nomenclature[B,02]{p}{pico \nomunit{$10^{-12}$}}
\nomenclature[B,03]{n}{nano \nomunit{$10^{-9}$}}
\nomenclature[B,04]{$\mu$}{micro \nomunit{$10^{-6}$}}
\nomenclature[B,05]{m}{mili \nomunit{$10^{-3}$}}
\nomenclature[B,06]{k}{kilo \nomunit{$10^{3}$}}
\nomenclature[B,07]{M}{mega \nomunit{$10^{6}$}}
\nomenclature[B,08]{G}{giga \nomunit{$10^{9}$}}
%Acronyms
\nomenclature[C]{ABC}{Text for ABC}
\nomenclature[C]{DEF long long long}{Very long long long long long long long long long long long long long long text for DEF}
\nomenclature[C]{GHI}{Text for GHI}

\printnomenclature
\end{document}

This is my output:

enter image description here

I want something like this:

enter image description here

I don't know if all my requests are possible, but helping me solving at least some of them would be really good. Thank you very much!

3

After pulling out the guts of nomencl and replacing them with metal parts, it seems to be alive!

enter image description here


Usage:

Different from the usual approach, of redefining the \nomgroup macro to add an \ifstrequal to select the header of the items, the modified form introduces a command:

\newsymbolclass[<ncols>]{<id>}{<title>}

which defines a "Symbol Class" called <title> and is printed in the Nomenclature with <ncols> columns.

Then each nomenclature entry is added with:

\addsymbol{<id>}[<sort-order>]{<symbol>}{<description>}

which has basically the same syntax as the old \nomenclature:

\nomenclature[<class><sort-order>]{<symbol>}{<description>}

except that the <class> is implicitly set according to the <id>.

One nice thing (in my opinion) is that this scheme does is that the order of appearance of the "lists-of" depends on the order of declaration of the symbol classes so, for example, the picture above was generated with:

\newsymbolclass[2]{unit}{Units}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass   {acro}{Acronyms}

but if we wanted, say, to make them in alphabetical order, we would need to use:

\newsymbolclass   {acro}{Acronyms}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass[2]{unit}{Units}

Each entry in the class is still sorted alphabetically by MakeIndex which obeys the given <sort-order>.


How it works:

First we load the multicol package for the columns, etoolbox for a few shorthands like \csedef, and enumitem because I still don't understand how LaTeX's "primitive" \list works :P

Then we define a couple of registers we're going to use. \@symsep is the blank space between the symbol and its description and \@symind is the indentation of the symbol.

The \nomenclheader macro is responsible for creating the header of each symbol class. Here I used a \subsubsection* for this.

The \thenomenclature environment is basically the same, except that the standard \list is removed. Later on the \nomgroup macro will start the list using \begin{enumerate}.

The \nomenclature macro is made inaccessible because it will not follow the rules of the new scheme. The error message tells the user to use the higher level \addsymbol instead. Of course, the macro still exists and is called \@nomenclature for the stubborn.

Now we start to build things. We first define the \newsymbolclass macro. This macro just does a bunch of definitions. Say, for example, we call:

\newsymbolclass[3]{pref}{Prefixes}

then we'll have:

\def\symb@pref{}% Just a dummy empty macro
\def\symb@pref@ord{A}% This replaces the old \ifstrequal{A}{Prefixes} syntax. This will be B for the next class and so on...
\def\symb@pref@wd{0pt}% This will be the width of the widest symbol
\def\symb@pref@nc{3}% The number of columns (#1)

with the definitions above we have almost all the settings we need. The problem is that the argument of \nomgroup is not the <id> (pref in this example), but the first letter of the alphabetical ordering argument (A in the example above). Basically, we know that pref means A, but \nomgroup doesn't know that A means pref, so we define:

\def\symb@A@name{pref}% A backreference
\def\symb@A@title{Prefixes}% The title, for convenience

Now we define the \addsymbol macro. This is just a fancy wrapper for the former \nomenclature macro. It will check if the given class exists, then it will measure the symbol and store the maximum with of the symbol in that symbol class. Finally, it calls the usual \nomenclature.

Now the actual typesetting macro is defined. The \nomgroup macro first checks if another \nomgroup is open and closes it, if needed (I admit, this is lazy programming :P). Then a \nomenclheader is issued with \symb@#1@title. We then check if the number of columns is larger than one and start a multicols if that's the case. Finally we fetch the width of the widest symbol, add the \@symsep, and pass everything as argument to the \begin{enumerate}.

That's it :)

I think that this version is much easier to customize, as the parameters can be changed in the optional argument to \begin{enumerate} and, modesty aside, I think that it is less messy than the other version.

% arara: pdflatex
% arara: nomencl
% arara: pdflatex

\documentclass{article}

\usepackage{amsmath}
\usepackage[spanish]{babel}
\usepackage[T1]{fontenc}
\usepackage[acronym]{glossaries}
\usepackage[utf8]{inputenc}
\usepackage[norefpage]{nomencl}
\usepackage{newmencl}

\begin{document}

Some text to compile.

\newsymbolclass[2]{unit}{Units}
\newsymbolclass[3]{pref}{Prefixes}
\newsymbolclass{acro}{Acronyms}

%Add units
\newcommand{\nomunit}[1]{%
  \renewcommand{\nomentryend}{\hspace*{\fill}\makebox[1cm][l]{#1}}%
  }

%Label width
\nomlabelwidth=10mm 

%Units
\addsymbol{unit}{Bq}{Becquerel \nomunit{1 des/s}}
\addsymbol{unit}{Ci}{Curie \nomunit{$3.7 \times 10^{10} Bq$}}
\addsymbol{unit}{N}{Newton \nomunit{$kg m/s^2$}}
\addsymbol{unit}{A}{Ampere \nomunit{c/s}}
%Prefixes
\addsymbol{pref}[01]{f}{femto \nomunit{$10^{-15}$}}
\addsymbol{pref}[02]{p}{pico \nomunit{$10^{-12}$}}
\addsymbol{pref}[03]{n}{nano \nomunit{$10^{-9}$}}
\addsymbol{pref}[04]{$\mu$}{micro \nomunit{$10^{-6}$}}
\addsymbol{pref}[05]{m}{mili \nomunit{$10^{-3}$}}
\addsymbol{pref}[06]{k}{kilo \nomunit{$10^{3}$}}
\addsymbol{pref}[07]{M}{mega \nomunit{$10^{6}$}}
\addsymbol{pref}[08]{G}{giga \nomunit{$10^{9}$}}
%Acronyms
\addsymbol{acro}{ABC}{Text for ABC}
\addsymbol{acro}{DEF long long long}{Very long long long long long long long long long long long long long long text for DEF}
\addsymbol{acro}{GHI}{Text for GHI}

\printnomenclature

\end{document}

And the newmencl (proto)-package is:

\ProvidesPackage{newmencl}
\RequirePackage{enumitem}
\RequirePackage{multicol}
\RequirePackage{etoolbox}
\RequirePackage{nomencl}
\newlist{nomencl}{enumerate}{1}
\setlist[nomencl]{%
  topsep=\z@,
  itemsep=\z@,
  labelindent=\@symind,
  labelwidth=\wd\tempbox@b,
  labelsep*=\@symsep,
  align=left,
  leftmargin=!,
}
\def\setnomencl#1{\setlist*[nomencl]{#1}}
\newbox\tempbox@b
\def\nomentryend{.}
\def\symbnodot{\let\nomentryend\relax}
\def\nomenclheader#1{\subsubsection*{#1}}
\newif\ifmustclose\mustclosefalse
\def\thenomenclature{%
  \@ifundefined{chapter}%
  {\section*{\nomname}%
   \if@intoc\addcontentsline{toc}{section}{\nomname}\fi}%
  {\chapter*{\nomname}%
   \if@intoc\addcontentsline{toc}{chapter}{\nomname}\fi}%
  \par\nompreamble}%
\def\endthenomenclature{%
  \end{nomencl}%
  \ifinmulticol
    \end{multicols}%
    \inmulticolfalse
  \fi
  \nompostamble}
\let\@@nomenclature\nomenclature
\def\nomenclature{%
  \PackageError{}{Don't use the \string\nomenclature\space command.%
     \MessageBreak Use the appropriate \string\addsymbol\space instead}%
    {}}
\newdimen\@symsep\@symsep=1em
\newdimen\@symind\@symind=1em
\newif\ifinmulticol
\def\nomgroup#1{%
  \edef\tempa{\@nameuse{symb@#1@nc}}
  \ifmustclose
    \end{nomencl}
    \ifinmulticol
      \end{multicols}%
      \inmulticolfalse
    \fi
  \fi\mustclosetrue
  \vskip\parskip
  \itemsep\z@
  \nomenclheader{\@nameuse{symb@#1@title}}%
  \setbox\tempbox@b\hbox{\@nameuse{symb@#1@widest}}%
  \expandafter\ifnum\csname symb@\@nameuse{symb@#1@name}@nc\endcsname>\@ne
    \inmulticoltrue
    \begin{multicols}{\@nameuse{symb@\@nameuse{symb@#1@name}@nc}}%
  \fi
  \begin{nomencl}}
\def\addsymbol#1{\@ifnextchar[%]
    {\@addsymbol{#1}}{\@symbolnoopt{#1}}}%
\def\@symbolnoopt#1#2{%
  \@addsymbol#1[{#2}]{#2}}
\def\@addsymbol#1[#2]#3#4{%
  \expandafter\ifx\csname symb@#1\endcsname\@empty\else
    \PackageError{}{%
      Class #1 undefined. Use \string\newsymbolclass{#1}}{}
  \fi
  \setbox\@tempboxa\hbox{#3}%
  \setbox\tempbox@b\hbox{\@nameuse{symb@#1@widest}}%
  \ifdim\wd\tempbox@b<\wd\@tempboxa
    \csgdef{symb@#1@widest}{#3}%
  \fi
  \@nomenclature[\@nameuse{symb@#1@ord}#2]{#3}{#4}%
  \ignorespaces}
\newcount\@nsymbcls
\def\newsymbolclass{\@ifnextchar[%]
  \@newsymbolclass{\@newsymbolclass[1]}}
\def\@newsymbolclass[#1]#2#3{%
  \expandafter\ifx\csname symb@#2\endcsname\@empty
    \PackageError{}{Symbol Class #2 already defined}{}
  \fi
  \global\advance\@nsymbcls\@ne
  \csgdef{symb@#2}{}%
  \csxdef{symb@#2@ord}{\@Alph\@nsymbcls}%
  \csgdef{symb@#2@widest}{}%
  \csxdef{symb@#2@nc}{#1}% Save number of columns
  \csxdef{symb@\@nameuse{symb@#2@ord}@name}{#2}% For backreference
  \protected@csxdef{symb@\@nameuse{symb@#2@ord}@title}{#3}}
\AtEndDocument{%
  \count@\z@
  \@whilenum\count@<\@nsymbcls\do{%
    \advance\count@\@ne
    \edef\@tempa{\@nameuse{symb@\@Alph\count@ @name}}%
    \toks@\expandafter\expandafter\expandafter
      {\csname symb@\@tempa @widest\endcsname}%
    \immediate\write\@auxout{%
      \gdef\expandonce{\csname symb@\@Alph\count@ @widest\endcsname}%
                      {\the\toks@}}}}%
\makenomenclature
\endinput

You can change the appearance of the list using the \setnomencl, which is a wrapper around \setlist*[nomencl].

2
  • 1
    THANK YOU VERY MUCH! That's exactly what I wanted! I've been reading what you wrote and trying to understand each part and I've tried it and it worked! Thank you very much for your time and help, I really appreciate it. And you're right, your version is more customizable and less messy. Thanks for it, @PhelypeOleinik ! May 22 '18 at 19:32
  • @G.Cuticchia Glad to help :) The section "How it works" is boring stuff mostly intended if you want to drastically change something in the working of the list. Otherwise the options passed to the \begin{enumerate} are usually enough. May 22 '18 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.