3

Glossary or Acronyms not showing as section headers in the appendix, and as such not on the table of contents.

I'd like it the table of contents and appendices to look like this.

Contents
1 Section Heading
A Appendix Heading
B Glossary
C Acronyms

Below is a short example of what I am doing.

\documentclass[twoside,12pt]{article}
\usepackage[a4paper,top=1in,bottom=1in,left=0.75in,right=0.75in,headheight=110pt]{geometry}
\usepackage[acronym]{glossaries}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{titletoc}

\makeglossaries
\newacronym{cd}{CD}{compact disk}
\newglossaryentry{api}
{
    name={API},
    plural={APIs},
    description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
    first={Application Programming Interface (API)},
    long={Application Programming Interface}
}

\title{TOC Example}

\begin{document}
\tableofcontents

\startcontents[mainsection]
\section{Section Heading}
\lipsum[1]
\gls{cd}
\gls{api}
\stopcontents[mainsection]

\appendix
\startcontents[appendices]
\section*{Appendices}
\section{Appendix Heading}
\lipsum[1]
\printglossaries

\end{document}
7
  • You need to use the toc package option to add the glossaries to the table of contents: \usepackage[acronym,toc]{glossaries} Apr 20, 2018 at 12:01
  • Related: Include glossary in table of contents Apr 20, 2018 at 12:02
  • I think @NicolaTalbot has a better idea of how to solve this, so I will defer to him on this.
    – AML
    Apr 20, 2018 at 12:25
  • If adding the toc package option provides a solution then this question can be closed as a duplicate of the one I linked to above. (I've got a gold glossaries badge which means if I vote to close this as a duplicate it will instantly be closed, so I'd rather get confirmation before doing that.) Apr 20, 2018 at 13:23
  • @NicolaTalbot I did try that and whilst you are correct in that it does add the glossaries to the table of contents it doesn't add them with a number which was what I was after.
    – AeroMaxx
    Apr 25, 2018 at 6:08

2 Answers 2

1

I've since worked out what I was wanting to do and the example code below works.

The command \renewcommand*{\glossarysection}[2][]{\section{#1}} rewrites the headings so that they are sections, which then get added to the table of contents and with a number, hope this helps someone!

    \documentclass[twoside,12pt]{article}
    \usepackage[a4paper,top=1in,bottom=1in,left=0.75in,right=0.75in,headheight=110pt]{geometry}
    \usepackage[acronym]{glossaries}
    \usepackage{graphicx}
    \usepackage{lipsum}
    \usepackage{titletoc}

    % Make glossaries
    \makeglossaries
    \renewcommand*{\glossarysection}[2][]{\section{#1}}

    \newacronym{cd}{CD}{compact disk}
    \newglossaryentry{api}
    {
        name={API},
        plural={APIs},
        description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
        first={Application Programming Interface (API)},
        long={Application Programming Interface}
    }

    \title{TOC Example}

    \begin{document}

    \tableofcontents

    % Start mainsection content to be included in table of contents
    \startcontents[mainsection]

    \section{Section Heading}
    \gls{api}

    % End mainsection content to be included in table of contents
    \stopcontents[mainsection]

    \clearpage

    \appendix

    % Start appendices content to be included in table of contents
    \startcontents[appendices]
    \section*{Appendices}

    \section{Appendix Heading}
    \lipsum[1]

    \printglossaries

    \end{document}
2
  • If you want numbered sections, it's simpler just to use the numberedsection package option. Your definition of \glossarysection uses the toctitle setting for both the header and table of contents. This may be okay for your particular use, but it's not a general purpose solution. Apr 25, 2018 at 8:14
  • @NicolaTalbot I just tried that and I can't seem to tell the difference between them, so I am using your simpler suggestion.
    – AeroMaxx
    Apr 25, 2018 at 10:37
0

As far as I can tell, you are simply labeling the \section{}s incorrectly. If you label them with what you want, then you get the TOC that you desire.

    \documentclass[twoside,12pt]{article}
    \usepackage[a4paper,top=1in,bottom=1in,left=0.75in,right=0.75in,headheight=110pt]{geometry}
    \usepackage[acronym]{glossaries}
    \usepackage{graphicx}
    \usepackage{lipsum}
    \usepackage{titletoc}

    % Make glossaries
    \makeglossaries
    \newacronym{cd}{CD}{compact disk}
    \newglossaryentry{api}
    {
        name={API},
        plural={APIs},
        description={An Application Programming Interface (API) is a particular set of rules and specifications that a software program can follow to access and make use of the services and resources provided by another particular software program that implements that API},
        first={Application Programming Interface (API)},
        long={Application Programming Interface}
    }

    \title{TOC Example}

    \begin{document}

    \tableofcontents

    % Start mainsection content to be included in table of contents
    \startcontents[mainsection]
    %\printcontents[mainsection]{l}{1}{\section*{Main Sections}\setcounter{tocdepth}{3}}

    \section{Section Heading}
    \lipsum[1]

    % End mainsection content to be included in table of contents
    \stopcontents[mainsection]

    \clearpage

    \appendix

    % Start appendices content to be included in table of contents
    \startcontents[appendices]
    \section*{Appendices}

    \section{Appendix Heading}
    \lipsum[1]

    \section{Glossary}
    \lipsum[1]

    \section{Acronyms}
    \lipsum[1]

    \printglossaries

    %----------------------------------------------------------------------------------------

    \end{document}

enter image description here

3
  • 1
    Could you add some explanation why this is a solution, please?
    – user31729
    Apr 19, 2018 at 18:20
  • Thanks for replying, but I don't think you understood my question, the \printglossaries prints out the headers for the Acronyms and the Glossaries so with your code I get duplicate headers, one from your section, and then another from the \printglossaries. So the example output you gave is what appears on the table of contents, but the headers are duplicated in the appendix itself.
    – AeroMaxx
    Apr 19, 2018 at 20:21
  • @AeroMaxx You're right, I thought it was just a TOC issue, based on your initial figure. Will work on the other part.
    – AML
    Apr 20, 2018 at 11:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .