TransWikia.com

Multi-column glossary style with descriptions wrapped inside their own column

TeX - LaTeX Asked by Sjiveru on January 7, 2021

I’m trying to make a multicolumn glossary style (with glossaries) that can handle long descriptions, but I’m rather unfamiliar with how to write a glossary style, and don’t exactly know how to pull it off.

What I’d like to have is a glossary with four columns; two pairs of abbreviation and description. If a description is more than one line, the description should only wrap within its own column, and the abbreviation column should skip however many lines to keep each abbreviation lined up with the start of its description.

All I know how to do is make two total columns and manually separate the abbreviation and the description; via this code (which I’m quite sure I copypasted off of StackExchange some while ago):

newglossarystyle{glossabbr}{%
renewenvironment{theglossary}%
{begin{multicols}{2}raggedright}
    {end{multicols}}

renewcommand*{glossaryheader}{}
renewcommand*{glsgroupheading}[1]{}
renewcommand*{glsgroupskip}{}
renewcommand*{glsclearpage}{} 

% set how each entry should appear:
renewcommand*{glossentry}[2]{
    noindentmakebox[7em][l]{glstarget{##1}{textsc{glossentryname{##1}}}}
    glossentrydesc{##1}
}
renewcommand*{subglossentry}[3]{%
    glossentry{##2}{##3}
}
}

The problem with this code is that when you have a long description, it just wraps over into the abbreviations column, because LaTeX isn’t treating the abbreviation and the description as separate blocks. You can see the problem here, highlighted in red:

Glossary with bad word wrap

Ultimately all I’d like to do is just take those wrapped description bits (the bits not in small caps) and shove them over, confining them in the column for descriptions and leaving whitespace in the abbreviations column where they are right now. How do I make that happen?

MWE with the problematic glossary style:

documentclass{article}

usepackage[acronym,nomain]{glossaries}
setacronymstyle{long-sc-short}
makeglossaries

newacronym
{inform}{inform}{informative illocutionary force}
newacronym
{point}{point}{demonstrative illocutionary force}

usepackage{multicol}
newglossarystyle{glossabbr}{%
    renewenvironment{theglossary}%
    {begin{multicols}{2}raggedright}
        {end{multicols}}
    
    renewcommand*{glossaryheader}{}
    renewcommand*{glsgroupheading}[1]{}
    renewcommand*{glsgroupskip}{}
    renewcommand*{glsclearpage}{} 
    
    % set how each entry should appear:
    renewcommand*{glossentry}[2]{
        noindentmakebox[7em][l]{glstarget{##1}{textsc{glossentryname{##1}}}}
        glossentrydesc{##1}
    }
    renewcommand*{subglossentry}[3]{%
        glossentry{##2}{##3}
    }
}

begin{document}

glsunsetall

gls{point}

gls{inform}

printglossary[style=glossabbr]

end{document}

One Answer

This should be a good start for a complete solution:

documentclass{article}

usepackage[acronym,nomain]{glossaries}
setacronymstyle{long-sc-short}
makeglossaries

newacronym
{inform}{inform}{informative illocutionary force}
newacronym
{point}{point}{demonstrative illocutionary force}

usepackage{multicol}
newglossarystyle{glossabbr}{%
    renewenvironment{theglossary}%
    {begin{multicols}{2}raggedright}
        {end{multicols}}
    
    renewcommand*{glossaryheader}{}
    renewcommand*{glsgroupheading}[1]{}
    renewcommand*{glsgroupskip}{}
    renewcommand*{glsclearpage}{} 
    
    % set how each entry should appear:
    renewcommand*{glossentry}[2]{
        noindentmakebox[7em][l]{glstarget{##1}%
            {begin{minipage}[t]{0.2textwidth}
                textsc{glossentryname{##1}}
            end{minipage}
        }}
        begin{minipage}{0.2textwidth}
        glossentrydesc{##1}
        end{minipage}
    }
    renewcommand*{subglossentry}[3]{%
        glossentry{##2}{##3}
    }
}

begin{document}

glsunsetall

gls{point}

gls{inform}

printglossary[style=glossabbr]

end{document}

Please note the added minipage environments around glossentryname and glossentrydesc. This is kind-of raw workaround.

You should try to tweak the environment to you needs - width could be increased (maybe, but this looks acceptable) and I am having trouble setting vertical alignment of glossary entry to top , not center.

I leave that up to your research ;)

Correct answer by Tomáš Kruliš on January 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP