[Tex/LaTex] Custom glossary style: Make glossary as wide as \textwidth

glossariestablestabularx

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.

Best Answer

"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.

Related Question