5

I am using the package glossaries to create a glossary in my document. The style super almost works for me, as it gives me two columns: the first with the glossary entry names and the second with the description. Both columns are left aligned.

Is it possible to right align the first column containing the glossary entry names?

This is what I would like to achieve:

This is what I want it to look like

And this is my code so far:

\documentclass{article}

\usepackage{glossaries}
\newglossaryentry{Example}{name=Example, description=an example}
\newglossaryentry{EX}{name=EX, description=another example}
\setglossarystyle{super}
\makeglossaries

\begin{document}

I use \gls{Example} and \gls{EX} in my text.

\printglossaries
\end{document}
8

To make them right aligned you need to modify the super glossary style. This is simple to do, but you need to look up the definition of the original style.

From glossary-super.sty:

\newglossarystyle{super}{%
  \renewenvironment{theglossary}%
    {\tablehead{}\tabletail{}%
     \begin{supertabular}{lp{\glsdescwidth}}}%
    {\end{supertabular}}%
  \renewcommand*{\glossaryheader}{}%
  \renewcommand*{\glsgroupheading}[1]{}%
  \renewcommand{\glossentry}[2]{%
    \glsentryitem{##1}\glstarget{##1}{\glossentryname{##1}} &
    \glossentrydesc{##1}\glspostdescription\space ##2\tabularnewline
  }%
  \renewcommand{\subglossentry}[3]{%
     &
     \glssubentryitem{##2}%
     \glstarget{##2}{\strut}\glosentrydesc{##2}\glspostdescription\space
     ##3\tabularnewline
  }%
  \renewcommand*{\glsgroupskip}{%
    \ifglsnogroupskip\else & \tabularnewline\fi}%
}

Since it is a super tabular environment you only need to change the \begin{supertabular}{lp{\glsdescwidth}} to \begin{supertabular}{rp{\glsdescwidth}}. To setup your own style based on an existing style example 20 in Sec. 15.2 from the glossaries user manual is helpful. For your case this is adding the following to your preamble:

\newglossarystyle{mysuper}{%
  \setglossarystyle{super}% base style on the list style
  \renewenvironment{theglossary}%
      {\tablehead{}\tabletail{}%
       \begin{supertabular}{rp{\glsdescwidth}}}%
      {\end{supertabular}}%
}

and to change \setglossarystyle{super} to \setglossarystyle{mysuper}.


The full change to your MWE would be this:

\documentclass{article}
\usepackage{glossaries}
\makeglossaries

\newglossarystyle{mysuper}{%
  \setglossarystyle{super}% base style on the list style
  \renewenvironment{theglossary}%
      {\tablehead{}\tabletail{}%
       \begin{supertabular}{rp{\glsdescwidth}}}%
      {\end{supertabular}}%
}
\setglossarystyle{mysuper}

\newglossaryentry{Example}{name=Example, description=an example}
\newglossaryentry{EX}{name=EX, description=another example}

\begin{document}

I use \gls{Example} and \gls{EX} in my text.

\printglossaries

\end{document}

resulting in:

mwe result


Note: I also changed where you define your entries to after \makeglossaries. In your case it didn't seem to matter, but is the recommended method in the manual.

  • How to add this same style per chapter glossary, acronym etc. I want to add this same style super per chapter glossary – Deb bijan Aug 15 '18 at 7:07

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.