9

WARNING: This is a follow-up question to Display long form (first-use like) entries of non-acronym-type entries.

As mafp suggested in the other post I went ahead and defined my own glossary-styles (along with some column specifiers) to tackle the unit issue (using the user1 field). Now my defintion looks like this (style tabx3col used in first glossary and tabx4col used in second):

\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\newglossarystyle{tabx3col}{%
 % put the glossary in a longtable environment:
 \renewenvironment{theglossary}%
  {\begin{longtable}{L{0.2\textwidth}L{0.6\textwidth}R{0.2\textwidth}}}%
  {\end{longtable}}%
 % Set the table's header:
 \renewcommand*{\glossaryheader}{}%
 % No heading between groups:
  \renewcommand*{\glsgroupheading}[1]{}%
 % Main (level 0) entries displayed in a row:
  \renewcommand*{\glossaryentryfield}[5]{%
    \glstarget{##1}{\textbf{##2}}% Name
    & ##3% Description
    & ##5% Page list
    \\% end of row
  }%
 % Sub entries treated the same as level 0 entries:
 %\renewcommand*{\glossarysubentryfield}[6]{%
  %\glossaryentryfield{##2}{##3}{##5}{##6}}%
 %% Nothing between groups:
 %\renewcommand*{\glsgroupskip}{}%
}


\newglossarystyle{tabx4col}{%
 % put the glossary in a longtable environment:
 \renewenvironment{theglossary}%
  {\begin{longtable}{L{0.1\textwidth}L{0.1\textwidth}p{0.55\textwidth}R{0.2\textwidth}}}%
  {\end{longtable}}%
 % Set the table's header:
 \renewcommand*{\glossaryheader}{}%
 % No heading between groups:
  \renewcommand*{\glsgroupheading}[1]{}%
 % Main (level 0) entries displayed in a row:
  \renewcommand*{\glossaryentryfield}[5]{%
   \glstarget{\textbf{##1}}{\textbf{##2}}% Name
   & $[$\glsentryuseri{##1}$]$% Units
   & ##3% Description
   & ##5% Page list
    \\% end of row
  }%
 % Sub entries treated the same as level 0 entries:
 %\renewcommand*{\glossarysubentryfield}[6]{%
  %\glossaryentryfield{##2}{##3}{##5}{##6}}%
 %% Nothing between groups:
 %\renewcommand*{\glsgroupskip}{}%
}

This gives me an output as shown in the image below: screenshot of output

I edit the screenshot with some grey lines for the text which i would like to align (Using the R column specifier for fixed-width raggedright columns used in the pagelist). Mainly I would like to have the whole glossary \textwidth. I thought by making every column dependant on the \textwidth variable and adding the values up to 1 I would get a table which ultimately is as wide as the headerline. I've also tried using tabularx as the table environment, which failed (even though using the macro commands, e.g., \tabularx \endtabularx ). I've compiled an MWE (http://pastebin.com/McqsTPga, maybe not so minimal anymore) where you can see the problem for yourself.

I'm sorry for the somewhat lengthy post, but this is really bugging me.

1
  • Thanks for sharing! I would like to use this for my own work, could you tell me, how I get the page numbers to show? Do they need to be specified manually in the glossary file or do I need a special package for it to work? Jul 23, 2017 at 22:08

2 Answers 2

4

"I thought by making every column dependant on the \textwidth variable and adding the values up to 1 I would get a table which ultimately is as wide as the headerline." This is almost true, but you forgot the intercolumn space that is automatically added. You can suppress that with @{} in the column specification. When I specify your tables with

\newglossarystyle{tabx3col}{%
 \renewenvironment{theglossary}%
  {\begin{longtable}{@{}p{0.2\textwidth}@{}p{0.6\textwidth}@{}>{\raggedleft}p{0.2\textwidth}@{}}}%
  ...

and

\newglossarystyle{tabx4col}{%
 \renewenvironment{theglossary}%
  {\begin{longtable}{@{}p{0.12\textwidth}@{}p{0.08\textwidth}@{}p{0.6\textwidth}@{}>{\raggedleft}p{0.2\textwidth}@{}}}%
  ...

the alignment comes out as desired. It may be a better idea to not suppress the intercolumn space before and after the description. Then you have to make the description column (or any other column) narrower by 24pt.

9
  • 1
    With the calc package you can do p{0.2\textwidth-2\tabcolsep} which takes care of the two "half paddings" relative to the column.
    – egreg
    Apr 5, 2013 at 11:38
  • Thanks again for your answer. Seriously how do you know this stuff ;-D. I copied and replaced my third line of code with yours, but i cant compile it. I get an error that says Exta alignment tab has been changed to \cr. Any idea? If i modify the code manually with the @{} but leave the redefined column specifiers it works, but the first row in the first column shows an @.
    – Sensei
    Apr 5, 2013 at 12:29
  • Never mind, it was the raggedleft construct. I deleted it, and replaced it by the previously devined R column type. Works like a charm now. Thought i should share this beauty ;-) Screenshot on Imgur.
    – Sensei
    Apr 5, 2013 at 12:46
  • --> By the way I have some questions regarding the glossaries package and since we're already on it: 1) How are the ##1 and so on keys set and where can i fond out about which value they represent and why do they have two hash tags # 2) In the second custom glossary style the name won't print out bold - in the first one it does. Why? 3) The optional argument of the renewcommand tells it how many placeholders it should expect. For the \glossaryentryfield the value is 5. I only count 4, which does not work while compiling.
    – Sensei
    Apr 5, 2013 at 12:54
  • @Sensei 1) The arguments are label, formatted name, description, symbol, number list. This is described in the glossaries manual, chapter 16. There are two hashes as they are parameters of \glossaryentryfield, not \renewcommand.
    – mafp
    Apr 5, 2013 at 15:22
3

With \usepackage{calc} you can specify your longtable alignment as

\begin{longtable}{
  @{} % suppress the space at the left
  L{0.1\textwidth-\tabcolsep}
  L{0.1\textwidth-2\tabcolsep}
  p{0.6\textwidth-2\tabcolsep}
  R{0.2\textwidth-\tabcolsep}
  @{} % suppress the space at the right
}

You may want to remove the intercolumn spaces in the widest column; in this case

\begin{longtable}{
  @{} % suppress the space at the left
  L{0.1\textwidth}
  L{0.1\textwidth}
  p{0.6\textwidth-6\tabcolsep}
  R{0.2\textwidth}
  @{} % suppress the space at the right
}

Each column is preceded and followed by a \tabcolsep wide space; you have four columns, so, after suppressing the left- and rightmost spaces, six of them remain.

2
  • 1
    Or you use \dimexpr ... \relax Apr 5, 2013 at 11:50
  • Thank you too for your answers, i already marked mafp's answer as the correct one. Never the less I tried them out and they worked great. Egreg's solutions seems like the cleanest to me. Thanks again.
    – Sensei
    Apr 5, 2013 at 13:34

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.