How to include only named sections or subsections in the table of contents











up vote
1
down vote

favorite












I have lots of little sections and subsections in an article. some of them have a title and some don't. Is it possible to have a table of contents where only the named sections/subsections appear in it?



chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}


I want only the sections and subsections named Alice, Ava, Bob, Charles to show up in the table of contents.










share|improve this question
























  • When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
    – Jhor
    Nov 20 at 7:21










  • Yes thats what I meant...fixed the title. thanks
    – smilingbuddha
    Nov 20 at 7:44















up vote
1
down vote

favorite












I have lots of little sections and subsections in an article. some of them have a title and some don't. Is it possible to have a table of contents where only the named sections/subsections appear in it?



chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}


I want only the sections and subsections named Alice, Ava, Bob, Charles to show up in the table of contents.










share|improve this question
























  • When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
    – Jhor
    Nov 20 at 7:21










  • Yes thats what I meant...fixed the title. thanks
    – smilingbuddha
    Nov 20 at 7:44













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have lots of little sections and subsections in an article. some of them have a title and some don't. Is it possible to have a table of contents where only the named sections/subsections appear in it?



chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}


I want only the sections and subsections named Alice, Ava, Bob, Charles to show up in the table of contents.










share|improve this question















I have lots of little sections and subsections in an article. some of them have a title and some don't. Is it possible to have a table of contents where only the named sections/subsections appear in it?



chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}


I want only the sections and subsections named Alice, Ava, Bob, Charles to show up in the table of contents.







table-of-contents






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 7:44

























asked Nov 20 at 2:40









smilingbuddha

7434915




7434915












  • When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
    – Jhor
    Nov 20 at 7:21










  • Yes thats what I meant...fixed the title. thanks
    – smilingbuddha
    Nov 20 at 7:44


















  • When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
    – Jhor
    Nov 20 at 7:21










  • Yes thats what I meant...fixed the title. thanks
    – smilingbuddha
    Nov 20 at 7:44
















When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
– Jhor
Nov 20 at 7:21




When you say "index" are you meaning "table of contents" ? Please be more specific, and help us to help you by providing a minimal working example (edit your post to add code).
– Jhor
Nov 20 at 7:21












Yes thats what I meant...fixed the title. thanks
– smilingbuddha
Nov 20 at 7:44




Yes thats what I meant...fixed the title. thanks
– smilingbuddha
Nov 20 at 7:44










3 Answers
3






active

oldest

votes

















up vote
3
down vote



accepted










With a standard class you could patch @sect:



documentclass{report}
usepackage{xpatch}
letoriginaladdcontentslineaddcontentsline
makeatletter
xpatchcmd@sect
{addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
{%
if!#7!else
originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
fi
}{}{PatchFailed}
xpatchcmd@sect
{addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
{%
if!#7!else
originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
fi
}{}{PatchFailed}
makeatother
begin{document}
tableofcontents
chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}
end{document}


Result:



enter image description here



But you could also use a KOMA-Script class. Then there would be no TOC entry for empty section titles by default:



documentclass{scrreprt}
begin{document}
tableofcontents
chapter{My chapter}
section{Alice}
section{}
subsection{}
subsection{Ava}
section{Bob}
section{}
section{}
section{Charles}
end{document}


Result:



enter image description here






share|improve this answer






























    up vote
    1
    down vote













    You need to redefine the tex macros that render the toc entry. That said, what you need to edit depends on the document class and the packages you include into your document. For the simplest latex book, no packages used, that would be something like



    makeatletter
    defl@section#1#2{%
    globalletoldnumlinenumberline
    defnumberline##1{}%
    if!#1!
    globalletnumberlineoldnumline
    else
    globalletnumberlineoldnumline
    @dottedtocline{1}{1.5em}{2.3em}{#1}{#2}%
    fi}
    defl@subsection#1#2{%
    globalletoldnumlinenumberline
    defnumberline##1{}%
    if!#1!
    globalletnumberlineoldnumline
    else
    globalletnumberlineoldnumline
    @dottedtocline{2}{3.8em}{3.2em}{#1}{#2}%
    fi}
    makeatother


    that you need to put before begin{document}.






    share|improve this answer























    • This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
      – esdd
      Nov 20 at 12:31










    • @esdd good point…
      – Lupino
      Nov 20 at 12:48


















    up vote
    0
    down vote













    With etoc you can have both types of tables of contents at the same time (with the standard classes).



    documentclass{report}

    usepackage{etoc}

    newcommand{trimmedtableofcontents}{%
    begingroup
    etocsetstyle{chapter}
    {}
    {ifxetocthenameempty
    else
    etocifnumbered
    {etocsavedchaptertocline
    {numberline{etocnumber}etocname}{etocpage}}
    {etocsavedchaptertocline{etocname}{etocpage}}%
    fi
    }%
    {}
    {}
    etocsetstyle{section}
    {}
    {ifxetocthenameempty
    else
    etocifnumbered
    {etocsavedsectiontocline
    {numberline{etocnumber}etocname}{etocpage}}
    {etocsavedsectiontocline{etocname}{etocpage}}%
    fi
    }%
    {}
    {}
    etocsetstyle{subsection}
    {}
    {ifxetocthenameempty
    else
    etocifnumbered
    {etocsavedsubsectiontocline
    {numberline{etocnumber}etocname}{etocpage}}
    {etocsavedsubsectiontocline{etocname}{etocpage}}%
    fi
    }%
    {}
    {}
    tableofcontents
    endgroup
    }

    begin{document}
    trimmedtableofcontents
    renewcommandcontentsname{Full table of contents}
    tableofcontents
    chapter{My chapter}
    section{Alice}
    section{}
    subsection{}
    subsection{Ava}
    section{Bob}
    section{}
    section{}
    section{Charles}
    end{document}


    First page:



    enter image description here



    Second page:



    enter image description here






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "85"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460868%2fhow-to-include-only-named-sections-or-subsections-in-the-table-of-contents%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote



      accepted










      With a standard class you could patch @sect:



      documentclass{report}
      usepackage{xpatch}
      letoriginaladdcontentslineaddcontentsline
      makeatletter
      xpatchcmd@sect
      {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
      {%
      if!#7!else
      originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
      fi
      }{}{PatchFailed}
      xpatchcmd@sect
      {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
      {%
      if!#7!else
      originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
      fi
      }{}{PatchFailed}
      makeatother
      begin{document}
      tableofcontents
      chapter{My chapter}
      section{Alice}
      section{}
      subsection{}
      subsection{Ava}
      section{Bob}
      section{}
      section{}
      section{Charles}
      end{document}


      Result:



      enter image description here



      But you could also use a KOMA-Script class. Then there would be no TOC entry for empty section titles by default:



      documentclass{scrreprt}
      begin{document}
      tableofcontents
      chapter{My chapter}
      section{Alice}
      section{}
      subsection{}
      subsection{Ava}
      section{Bob}
      section{}
      section{}
      section{Charles}
      end{document}


      Result:



      enter image description here






      share|improve this answer



























        up vote
        3
        down vote



        accepted










        With a standard class you could patch @sect:



        documentclass{report}
        usepackage{xpatch}
        letoriginaladdcontentslineaddcontentsline
        makeatletter
        xpatchcmd@sect
        {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
        {%
        if!#7!else
        originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
        fi
        }{}{PatchFailed}
        xpatchcmd@sect
        {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
        {%
        if!#7!else
        originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
        fi
        }{}{PatchFailed}
        makeatother
        begin{document}
        tableofcontents
        chapter{My chapter}
        section{Alice}
        section{}
        subsection{}
        subsection{Ava}
        section{Bob}
        section{}
        section{}
        section{Charles}
        end{document}


        Result:



        enter image description here



        But you could also use a KOMA-Script class. Then there would be no TOC entry for empty section titles by default:



        documentclass{scrreprt}
        begin{document}
        tableofcontents
        chapter{My chapter}
        section{Alice}
        section{}
        subsection{}
        subsection{Ava}
        section{Bob}
        section{}
        section{}
        section{Charles}
        end{document}


        Result:



        enter image description here






        share|improve this answer

























          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          With a standard class you could patch @sect:



          documentclass{report}
          usepackage{xpatch}
          letoriginaladdcontentslineaddcontentsline
          makeatletter
          xpatchcmd@sect
          {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
          {%
          if!#7!else
          originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
          fi
          }{}{PatchFailed}
          xpatchcmd@sect
          {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
          {%
          if!#7!else
          originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
          fi
          }{}{PatchFailed}
          makeatother
          begin{document}
          tableofcontents
          chapter{My chapter}
          section{Alice}
          section{}
          subsection{}
          subsection{Ava}
          section{Bob}
          section{}
          section{}
          section{Charles}
          end{document}


          Result:



          enter image description here



          But you could also use a KOMA-Script class. Then there would be no TOC entry for empty section titles by default:



          documentclass{scrreprt}
          begin{document}
          tableofcontents
          chapter{My chapter}
          section{Alice}
          section{}
          subsection{}
          subsection{Ava}
          section{Bob}
          section{}
          section{}
          section{Charles}
          end{document}


          Result:



          enter image description here






          share|improve this answer














          With a standard class you could patch @sect:



          documentclass{report}
          usepackage{xpatch}
          letoriginaladdcontentslineaddcontentsline
          makeatletter
          xpatchcmd@sect
          {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
          {%
          if!#7!else
          originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
          fi
          }{}{PatchFailed}
          xpatchcmd@sect
          {addcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}}
          {%
          if!#7!else
          originaladdcontentsline {toc}{#1}{ifnum #2>c@secnumdepth else protect numberline {csname the#1endcsname }fi #7}%
          fi
          }{}{PatchFailed}
          makeatother
          begin{document}
          tableofcontents
          chapter{My chapter}
          section{Alice}
          section{}
          subsection{}
          subsection{Ava}
          section{Bob}
          section{}
          section{}
          section{Charles}
          end{document}


          Result:



          enter image description here



          But you could also use a KOMA-Script class. Then there would be no TOC entry for empty section titles by default:



          documentclass{scrreprt}
          begin{document}
          tableofcontents
          chapter{My chapter}
          section{Alice}
          section{}
          subsection{}
          subsection{Ava}
          section{Bob}
          section{}
          section{}
          section{Charles}
          end{document}


          Result:



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 20 at 14:54

























          answered Nov 20 at 11:08









          esdd

          57.8k34485




          57.8k34485






















              up vote
              1
              down vote













              You need to redefine the tex macros that render the toc entry. That said, what you need to edit depends on the document class and the packages you include into your document. For the simplest latex book, no packages used, that would be something like



              makeatletter
              defl@section#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{1}{1.5em}{2.3em}{#1}{#2}%
              fi}
              defl@subsection#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{2}{3.8em}{3.2em}{#1}{#2}%
              fi}
              makeatother


              that you need to put before begin{document}.






              share|improve this answer























              • This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
                – esdd
                Nov 20 at 12:31










              • @esdd good point…
                – Lupino
                Nov 20 at 12:48















              up vote
              1
              down vote













              You need to redefine the tex macros that render the toc entry. That said, what you need to edit depends on the document class and the packages you include into your document. For the simplest latex book, no packages used, that would be something like



              makeatletter
              defl@section#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{1}{1.5em}{2.3em}{#1}{#2}%
              fi}
              defl@subsection#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{2}{3.8em}{3.2em}{#1}{#2}%
              fi}
              makeatother


              that you need to put before begin{document}.






              share|improve this answer























              • This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
                – esdd
                Nov 20 at 12:31










              • @esdd good point…
                – Lupino
                Nov 20 at 12:48













              up vote
              1
              down vote










              up vote
              1
              down vote









              You need to redefine the tex macros that render the toc entry. That said, what you need to edit depends on the document class and the packages you include into your document. For the simplest latex book, no packages used, that would be something like



              makeatletter
              defl@section#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{1}{1.5em}{2.3em}{#1}{#2}%
              fi}
              defl@subsection#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{2}{3.8em}{3.2em}{#1}{#2}%
              fi}
              makeatother


              that you need to put before begin{document}.






              share|improve this answer














              You need to redefine the tex macros that render the toc entry. That said, what you need to edit depends on the document class and the packages you include into your document. For the simplest latex book, no packages used, that would be something like



              makeatletter
              defl@section#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{1}{1.5em}{2.3em}{#1}{#2}%
              fi}
              defl@subsection#1#2{%
              globalletoldnumlinenumberline
              defnumberline##1{}%
              if!#1!
              globalletnumberlineoldnumline
              else
              globalletnumberlineoldnumline
              @dottedtocline{2}{3.8em}{3.2em}{#1}{#2}%
              fi}
              makeatother


              that you need to put before begin{document}.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Nov 20 at 12:58

























              answered Nov 20 at 8:02









              Lupino

              1,039610




              1,039610












              • This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
                – esdd
                Nov 20 at 12:31










              • @esdd good point…
                – Lupino
                Nov 20 at 12:48


















              • This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
                – esdd
                Nov 20 at 12:31










              • @esdd good point…
                – Lupino
                Nov 20 at 12:48
















              This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
              – esdd
              Nov 20 at 12:31




              This does not work, because the first argument of l@section or l@subscetion incudes numberline{<number>} if the section or subsection is numbered.
              – esdd
              Nov 20 at 12:31












              @esdd good point…
              – Lupino
              Nov 20 at 12:48




              @esdd good point…
              – Lupino
              Nov 20 at 12:48










              up vote
              0
              down vote













              With etoc you can have both types of tables of contents at the same time (with the standard classes).



              documentclass{report}

              usepackage{etoc}

              newcommand{trimmedtableofcontents}{%
              begingroup
              etocsetstyle{chapter}
              {}
              {ifxetocthenameempty
              else
              etocifnumbered
              {etocsavedchaptertocline
              {numberline{etocnumber}etocname}{etocpage}}
              {etocsavedchaptertocline{etocname}{etocpage}}%
              fi
              }%
              {}
              {}
              etocsetstyle{section}
              {}
              {ifxetocthenameempty
              else
              etocifnumbered
              {etocsavedsectiontocline
              {numberline{etocnumber}etocname}{etocpage}}
              {etocsavedsectiontocline{etocname}{etocpage}}%
              fi
              }%
              {}
              {}
              etocsetstyle{subsection}
              {}
              {ifxetocthenameempty
              else
              etocifnumbered
              {etocsavedsubsectiontocline
              {numberline{etocnumber}etocname}{etocpage}}
              {etocsavedsubsectiontocline{etocname}{etocpage}}%
              fi
              }%
              {}
              {}
              tableofcontents
              endgroup
              }

              begin{document}
              trimmedtableofcontents
              renewcommandcontentsname{Full table of contents}
              tableofcontents
              chapter{My chapter}
              section{Alice}
              section{}
              subsection{}
              subsection{Ava}
              section{Bob}
              section{}
              section{}
              section{Charles}
              end{document}


              First page:



              enter image description here



              Second page:



              enter image description here






              share|improve this answer

























                up vote
                0
                down vote













                With etoc you can have both types of tables of contents at the same time (with the standard classes).



                documentclass{report}

                usepackage{etoc}

                newcommand{trimmedtableofcontents}{%
                begingroup
                etocsetstyle{chapter}
                {}
                {ifxetocthenameempty
                else
                etocifnumbered
                {etocsavedchaptertocline
                {numberline{etocnumber}etocname}{etocpage}}
                {etocsavedchaptertocline{etocname}{etocpage}}%
                fi
                }%
                {}
                {}
                etocsetstyle{section}
                {}
                {ifxetocthenameempty
                else
                etocifnumbered
                {etocsavedsectiontocline
                {numberline{etocnumber}etocname}{etocpage}}
                {etocsavedsectiontocline{etocname}{etocpage}}%
                fi
                }%
                {}
                {}
                etocsetstyle{subsection}
                {}
                {ifxetocthenameempty
                else
                etocifnumbered
                {etocsavedsubsectiontocline
                {numberline{etocnumber}etocname}{etocpage}}
                {etocsavedsubsectiontocline{etocname}{etocpage}}%
                fi
                }%
                {}
                {}
                tableofcontents
                endgroup
                }

                begin{document}
                trimmedtableofcontents
                renewcommandcontentsname{Full table of contents}
                tableofcontents
                chapter{My chapter}
                section{Alice}
                section{}
                subsection{}
                subsection{Ava}
                section{Bob}
                section{}
                section{}
                section{Charles}
                end{document}


                First page:



                enter image description here



                Second page:



                enter image description here






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  With etoc you can have both types of tables of contents at the same time (with the standard classes).



                  documentclass{report}

                  usepackage{etoc}

                  newcommand{trimmedtableofcontents}{%
                  begingroup
                  etocsetstyle{chapter}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedchaptertocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedchaptertocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  etocsetstyle{section}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedsectiontocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedsectiontocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  etocsetstyle{subsection}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedsubsectiontocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedsubsectiontocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  tableofcontents
                  endgroup
                  }

                  begin{document}
                  trimmedtableofcontents
                  renewcommandcontentsname{Full table of contents}
                  tableofcontents
                  chapter{My chapter}
                  section{Alice}
                  section{}
                  subsection{}
                  subsection{Ava}
                  section{Bob}
                  section{}
                  section{}
                  section{Charles}
                  end{document}


                  First page:



                  enter image description here



                  Second page:



                  enter image description here






                  share|improve this answer












                  With etoc you can have both types of tables of contents at the same time (with the standard classes).



                  documentclass{report}

                  usepackage{etoc}

                  newcommand{trimmedtableofcontents}{%
                  begingroup
                  etocsetstyle{chapter}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedchaptertocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedchaptertocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  etocsetstyle{section}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedsectiontocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedsectiontocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  etocsetstyle{subsection}
                  {}
                  {ifxetocthenameempty
                  else
                  etocifnumbered
                  {etocsavedsubsectiontocline
                  {numberline{etocnumber}etocname}{etocpage}}
                  {etocsavedsubsectiontocline{etocname}{etocpage}}%
                  fi
                  }%
                  {}
                  {}
                  tableofcontents
                  endgroup
                  }

                  begin{document}
                  trimmedtableofcontents
                  renewcommandcontentsname{Full table of contents}
                  tableofcontents
                  chapter{My chapter}
                  section{Alice}
                  section{}
                  subsection{}
                  subsection{Ava}
                  section{Bob}
                  section{}
                  section{}
                  section{Charles}
                  end{document}


                  First page:



                  enter image description here



                  Second page:



                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 at 8:58









                  jfbu

                  44.5k65143




                  44.5k65143






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460868%2fhow-to-include-only-named-sections-or-subsections-in-the-table-of-contents%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to change which sound is reproduced for terminal bell?

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents