[Tex/LaTex] Increase description width and number list width in glossary to match table of contents

glossariestable of contents

I want my glossary created via glossaries (bottom) to have the same width as my table of contents (top). I would like the numbers in the glossary to have a large space away from the dots and description text equal to that in the table of contents.

compare

I feel that this is partly possible by modifying the description width via \glsdescwidth.

Here is a minimal working example:

\documentclass{report}

\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\usepackage[toc]{glossaries}
\makeglossaries
\renewcommand*\glspostdescription{\cftdotfill{\cftsecdotsep}}

\begin{document}

\tableofcontents

\newglossaryentry{K}{name={kind of long name},description={King of long description}}

\newglossaryentry{S}{name={some long name},description={Super super super super super super super super super super super super super super super super super long description}}

\printglossary[style=long]

\chapter{Chap 1}

\gls{K}

\gls{S}

\end{document}

To compile the example, you must use makeglossaries in between calls to latex.

Best Answer

Maybe something along these lines is a start? This works at least as long as there aren't too many page numbers for an entry in the glossary:

% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{report}

\usepackage{tocloft}
\renewcommand{\cftchapleader}{\cftdotfill{\cftsecdotsep}}

\usepackage[toc]{glossaries}
\makeglossaries

% tabular goodies:
\usepackage{array}

% a bigger glossary description width:
\setlength\glsdescwidth{.7\textwidth}

% adapt `long' glossarystyle
\newglossarystyle{mylong}{%
  \glossarystyle{long}% base this style on the `long' style
  % no indent before the longtable:
  \setlength\LTleft{0pt}%
  % the following relies on the `tocloft' package being loaded;
  % formatting of page numbers:
  \renewcommand\cftchappagefont{}%
  % renew the table: both columns together now have \textwidth:
  \renewenvironment{theglossary}%
    {%
      \begin{longtable}
        {
          @{}>{\raggedright}
            p{\dimexpr\textwidth-\glsdescwidth-2\tabcolsep\relax}
          p{\glsdescwidth}
          @{}
        }
    }%
    {\end{longtable}}%
  % the entry is formatted with \cftchapfilnum instead of
  % \glspostdescription:
  \renewcommand*{\glossaryentryfield}[5]{%
    \glsentryitem{##1}\glstarget{##1}{##2} &
    ##3%\glspostdescription
    \cftchapfillnum{##5}\\
  }%
}

% show page dimensions:
\usepackage{showframe}

\begin{document}

\tableofcontents

\newglossaryentry{K}{
  name={kind of long name},
  description={King of long description}}

\newglossaryentry{S}{
  name={some long name},
  description={Super super super super super super super super super super
    super super super super super super super long description}}

{\let\clearpage\relax% never do this! only for demonstration purposes!
\printglossary[style=mylong]
}

\chapter{Chap 1}

\gls{K} \gls{S}

\end{document}

enter image description here

Related Question