Centred “Contents” in TOC in twocolumn document with custom sections











up vote
3
down vote

favorite












I want to adjust the TOC for my twocolumn document. I want to have the word "Contents" at the top and centre of the page, and the toc entries following in two columns afterwards.



I found this which shows me how to do this; but



1) it conflicts with my use of the titletoc and titlesec packages. This is because the TOC seems itself to be a section.



2) it is overly specific in formatting of the toc entries.
I would like to format the entries themselves with titletoc as follows



titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}



How can I get my formatting of the sections and toc entries, as well as centering the word "Contents" in the TOC of my doc?



The result so far is this
Imgur



The MWE is:



documentclass[12pt,oneside,twocolumn]{article}
usepackage[a4paper, bottom=2cm, columnsep=2.0cm,top=2cm, left=1in, right=1cm ] {geometry}
usepackage{titlesec}
usepackage{titletoc}
titlespacing{section}{0pt}{4ex}{-0.5parskip}
titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

makeatletter
renewcommand*{tableofcontents}{%
if@twocolumn
@restonecolfalse
else
@restonecoltrue
fi
twocolumn[section*{centeringcontentsname}]%
@mkboth{MakeUppercasecontentsname}%
{MakeUppercasecontentsname}%
thispagestyle{plain}%
@starttoc{toc}%
if@restonecol
onecolumn
else
clearpage
fi
}
makeatother
begin{document}
tableofcontents
newpage

section{Section 1}
section{Section 2}
section{Section 3}
section{Section 4}
section{Section 5}
section{Section 6}
section{Section 7}
section{Section 8}
section{Section 9}
section{Section 10}
section{Section 11}
section{Section 12}
section{Section 13}
section{Section 14}
section{Section 15}
section{Section 16}
section{Section 17}
section{Section 18}
section{Section 19}
section{Section 20}
section{Section 21}
section{Section 22}
section{Section 23}
section{Section 24}
section{Section 25}
section{Section 26}
section{Section 27}
section{Section 28}
section{Section 29}

end{document}









share|improve this question
















bumped to the homepage by Community 3 hours ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.



















    up vote
    3
    down vote

    favorite












    I want to adjust the TOC for my twocolumn document. I want to have the word "Contents" at the top and centre of the page, and the toc entries following in two columns afterwards.



    I found this which shows me how to do this; but



    1) it conflicts with my use of the titletoc and titlesec packages. This is because the TOC seems itself to be a section.



    2) it is overly specific in formatting of the toc entries.
    I would like to format the entries themselves with titletoc as follows



    titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}



    How can I get my formatting of the sections and toc entries, as well as centering the word "Contents" in the TOC of my doc?



    The result so far is this
    Imgur



    The MWE is:



    documentclass[12pt,oneside,twocolumn]{article}
    usepackage[a4paper, bottom=2cm, columnsep=2.0cm,top=2cm, left=1in, right=1cm ] {geometry}
    usepackage{titlesec}
    usepackage{titletoc}
    titlespacing{section}{0pt}{4ex}{-0.5parskip}
    titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

    makeatletter
    renewcommand*{tableofcontents}{%
    if@twocolumn
    @restonecolfalse
    else
    @restonecoltrue
    fi
    twocolumn[section*{centeringcontentsname}]%
    @mkboth{MakeUppercasecontentsname}%
    {MakeUppercasecontentsname}%
    thispagestyle{plain}%
    @starttoc{toc}%
    if@restonecol
    onecolumn
    else
    clearpage
    fi
    }
    makeatother
    begin{document}
    tableofcontents
    newpage

    section{Section 1}
    section{Section 2}
    section{Section 3}
    section{Section 4}
    section{Section 5}
    section{Section 6}
    section{Section 7}
    section{Section 8}
    section{Section 9}
    section{Section 10}
    section{Section 11}
    section{Section 12}
    section{Section 13}
    section{Section 14}
    section{Section 15}
    section{Section 16}
    section{Section 17}
    section{Section 18}
    section{Section 19}
    section{Section 20}
    section{Section 21}
    section{Section 22}
    section{Section 23}
    section{Section 24}
    section{Section 25}
    section{Section 26}
    section{Section 27}
    section{Section 28}
    section{Section 29}

    end{document}









    share|improve this question
















    bumped to the homepage by Community 3 hours ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

















      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I want to adjust the TOC for my twocolumn document. I want to have the word "Contents" at the top and centre of the page, and the toc entries following in two columns afterwards.



      I found this which shows me how to do this; but



      1) it conflicts with my use of the titletoc and titlesec packages. This is because the TOC seems itself to be a section.



      2) it is overly specific in formatting of the toc entries.
      I would like to format the entries themselves with titletoc as follows



      titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}



      How can I get my formatting of the sections and toc entries, as well as centering the word "Contents" in the TOC of my doc?



      The result so far is this
      Imgur



      The MWE is:



      documentclass[12pt,oneside,twocolumn]{article}
      usepackage[a4paper, bottom=2cm, columnsep=2.0cm,top=2cm, left=1in, right=1cm ] {geometry}
      usepackage{titlesec}
      usepackage{titletoc}
      titlespacing{section}{0pt}{4ex}{-0.5parskip}
      titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

      makeatletter
      renewcommand*{tableofcontents}{%
      if@twocolumn
      @restonecolfalse
      else
      @restonecoltrue
      fi
      twocolumn[section*{centeringcontentsname}]%
      @mkboth{MakeUppercasecontentsname}%
      {MakeUppercasecontentsname}%
      thispagestyle{plain}%
      @starttoc{toc}%
      if@restonecol
      onecolumn
      else
      clearpage
      fi
      }
      makeatother
      begin{document}
      tableofcontents
      newpage

      section{Section 1}
      section{Section 2}
      section{Section 3}
      section{Section 4}
      section{Section 5}
      section{Section 6}
      section{Section 7}
      section{Section 8}
      section{Section 9}
      section{Section 10}
      section{Section 11}
      section{Section 12}
      section{Section 13}
      section{Section 14}
      section{Section 15}
      section{Section 16}
      section{Section 17}
      section{Section 18}
      section{Section 19}
      section{Section 20}
      section{Section 21}
      section{Section 22}
      section{Section 23}
      section{Section 24}
      section{Section 25}
      section{Section 26}
      section{Section 27}
      section{Section 28}
      section{Section 29}

      end{document}









      share|improve this question















      I want to adjust the TOC for my twocolumn document. I want to have the word "Contents" at the top and centre of the page, and the toc entries following in two columns afterwards.



      I found this which shows me how to do this; but



      1) it conflicts with my use of the titletoc and titlesec packages. This is because the TOC seems itself to be a section.



      2) it is overly specific in formatting of the toc entries.
      I would like to format the entries themselves with titletoc as follows



      titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}



      How can I get my formatting of the sections and toc entries, as well as centering the word "Contents" in the TOC of my doc?



      The result so far is this
      Imgur



      The MWE is:



      documentclass[12pt,oneside,twocolumn]{article}
      usepackage[a4paper, bottom=2cm, columnsep=2.0cm,top=2cm, left=1in, right=1cm ] {geometry}
      usepackage{titlesec}
      usepackage{titletoc}
      titlespacing{section}{0pt}{4ex}{-0.5parskip}
      titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

      makeatletter
      renewcommand*{tableofcontents}{%
      if@twocolumn
      @restonecolfalse
      else
      @restonecoltrue
      fi
      twocolumn[section*{centeringcontentsname}]%
      @mkboth{MakeUppercasecontentsname}%
      {MakeUppercasecontentsname}%
      thispagestyle{plain}%
      @starttoc{toc}%
      if@restonecol
      onecolumn
      else
      clearpage
      fi
      }
      makeatother
      begin{document}
      tableofcontents
      newpage

      section{Section 1}
      section{Section 2}
      section{Section 3}
      section{Section 4}
      section{Section 5}
      section{Section 6}
      section{Section 7}
      section{Section 8}
      section{Section 9}
      section{Section 10}
      section{Section 11}
      section{Section 12}
      section{Section 13}
      section{Section 14}
      section{Section 15}
      section{Section 16}
      section{Section 17}
      section{Section 18}
      section{Section 19}
      section{Section 20}
      section{Section 21}
      section{Section 22}
      section{Section 23}
      section{Section 24}
      section{Section 25}
      section{Section 26}
      section{Section 27}
      section{Section 28}
      section{Section 29}

      end{document}






      table-of-contents two-column titletoc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 13 '17 at 12:35









      Community

      1




      1










      asked Dec 22 '15 at 17:04









      Tim

      732513




      732513





      bumped to the homepage by Community 3 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 3 hours ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Perhaps not as elegant as what you are trying, but:



          Since the table of contents is only going to appear once, it's easy enough to remove the header and add a new one back in 'by hand'. Also, if you are mixing one-column and two-column elements, the multicol package is a little more flexible than setting the entire document to twocolumn.



          EDIT: My original solution didn't work with titlesec, I think I was using the section* macro in a way that was incompatible with that package. This seems to work now, with a manually formatted toc heading.



          documentclass{article}
          usepackage{multicol}

          usepackage{titlesec}
          titlespacing{section}{0pt}{4ex}{-0.5parskip}
          titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

          usepackage{titletoc}
          titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}

          makeatletter
          renewcommandtableofcontents{%
          @starttoc{toc}%
          }
          makeatother
          makeatletter
          renewcommandtableofcontents{%
          @starttoc{toc}%
          }
          makeatother

          begin{document}

          begin{center}
          Large
          textbf{Contents}
          end{center}

          begin{multicols}{2}

          tableofcontents
          newpage

          section{Section 1}
          section{Section 2}
          section{Section 3}
          section{Section 4}
          section{Section 5}
          section{Section 6}
          section{Section 7}
          section{Section 8}
          section{Section 9}
          section{Section 10}
          section{Section 11}
          section{Section 12}
          section{Section 13}
          section{Section 14}
          section{Section 15}
          section{Section 16}
          section{Section 17}
          section{Section 18}
          section{Section 19}
          section{Section 20}
          section{Section 21}
          section{Section 22}
          section{Section 23}
          section{Section 24}
          section{Section 25}
          section{Section 26}
          section{Section 27}
          section{Section 28}
          section{Section 29}
          end{multicols}


          end{document}


          LaTeX output






          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%2f284334%2fcentred-contents-in-toc-in-twocolumn-document-with-custom-sections%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Perhaps not as elegant as what you are trying, but:



            Since the table of contents is only going to appear once, it's easy enough to remove the header and add a new one back in 'by hand'. Also, if you are mixing one-column and two-column elements, the multicol package is a little more flexible than setting the entire document to twocolumn.



            EDIT: My original solution didn't work with titlesec, I think I was using the section* macro in a way that was incompatible with that package. This seems to work now, with a manually formatted toc heading.



            documentclass{article}
            usepackage{multicol}

            usepackage{titlesec}
            titlespacing{section}{0pt}{4ex}{-0.5parskip}
            titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

            usepackage{titletoc}
            titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}

            makeatletter
            renewcommandtableofcontents{%
            @starttoc{toc}%
            }
            makeatother
            makeatletter
            renewcommandtableofcontents{%
            @starttoc{toc}%
            }
            makeatother

            begin{document}

            begin{center}
            Large
            textbf{Contents}
            end{center}

            begin{multicols}{2}

            tableofcontents
            newpage

            section{Section 1}
            section{Section 2}
            section{Section 3}
            section{Section 4}
            section{Section 5}
            section{Section 6}
            section{Section 7}
            section{Section 8}
            section{Section 9}
            section{Section 10}
            section{Section 11}
            section{Section 12}
            section{Section 13}
            section{Section 14}
            section{Section 15}
            section{Section 16}
            section{Section 17}
            section{Section 18}
            section{Section 19}
            section{Section 20}
            section{Section 21}
            section{Section 22}
            section{Section 23}
            section{Section 24}
            section{Section 25}
            section{Section 26}
            section{Section 27}
            section{Section 28}
            section{Section 29}
            end{multicols}


            end{document}


            LaTeX output






            share|improve this answer



























              up vote
              0
              down vote













              Perhaps not as elegant as what you are trying, but:



              Since the table of contents is only going to appear once, it's easy enough to remove the header and add a new one back in 'by hand'. Also, if you are mixing one-column and two-column elements, the multicol package is a little more flexible than setting the entire document to twocolumn.



              EDIT: My original solution didn't work with titlesec, I think I was using the section* macro in a way that was incompatible with that package. This seems to work now, with a manually formatted toc heading.



              documentclass{article}
              usepackage{multicol}

              usepackage{titlesec}
              titlespacing{section}{0pt}{4ex}{-0.5parskip}
              titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

              usepackage{titletoc}
              titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}

              makeatletter
              renewcommandtableofcontents{%
              @starttoc{toc}%
              }
              makeatother
              makeatletter
              renewcommandtableofcontents{%
              @starttoc{toc}%
              }
              makeatother

              begin{document}

              begin{center}
              Large
              textbf{Contents}
              end{center}

              begin{multicols}{2}

              tableofcontents
              newpage

              section{Section 1}
              section{Section 2}
              section{Section 3}
              section{Section 4}
              section{Section 5}
              section{Section 6}
              section{Section 7}
              section{Section 8}
              section{Section 9}
              section{Section 10}
              section{Section 11}
              section{Section 12}
              section{Section 13}
              section{Section 14}
              section{Section 15}
              section{Section 16}
              section{Section 17}
              section{Section 18}
              section{Section 19}
              section{Section 20}
              section{Section 21}
              section{Section 22}
              section{Section 23}
              section{Section 24}
              section{Section 25}
              section{Section 26}
              section{Section 27}
              section{Section 28}
              section{Section 29}
              end{multicols}


              end{document}


              LaTeX output






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                Perhaps not as elegant as what you are trying, but:



                Since the table of contents is only going to appear once, it's easy enough to remove the header and add a new one back in 'by hand'. Also, if you are mixing one-column and two-column elements, the multicol package is a little more flexible than setting the entire document to twocolumn.



                EDIT: My original solution didn't work with titlesec, I think I was using the section* macro in a way that was incompatible with that package. This seems to work now, with a manually formatted toc heading.



                documentclass{article}
                usepackage{multicol}

                usepackage{titlesec}
                titlespacing{section}{0pt}{4ex}{-0.5parskip}
                titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

                usepackage{titletoc}
                titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}

                makeatletter
                renewcommandtableofcontents{%
                @starttoc{toc}%
                }
                makeatother
                makeatletter
                renewcommandtableofcontents{%
                @starttoc{toc}%
                }
                makeatother

                begin{document}

                begin{center}
                Large
                textbf{Contents}
                end{center}

                begin{multicols}{2}

                tableofcontents
                newpage

                section{Section 1}
                section{Section 2}
                section{Section 3}
                section{Section 4}
                section{Section 5}
                section{Section 6}
                section{Section 7}
                section{Section 8}
                section{Section 9}
                section{Section 10}
                section{Section 11}
                section{Section 12}
                section{Section 13}
                section{Section 14}
                section{Section 15}
                section{Section 16}
                section{Section 17}
                section{Section 18}
                section{Section 19}
                section{Section 20}
                section{Section 21}
                section{Section 22}
                section{Section 23}
                section{Section 24}
                section{Section 25}
                section{Section 26}
                section{Section 27}
                section{Section 28}
                section{Section 29}
                end{multicols}


                end{document}


                LaTeX output






                share|improve this answer














                Perhaps not as elegant as what you are trying, but:



                Since the table of contents is only going to appear once, it's easy enough to remove the header and add a new one back in 'by hand'. Also, if you are mixing one-column and two-column elements, the multicol package is a little more flexible than setting the entire document to twocolumn.



                EDIT: My original solution didn't work with titlesec, I think I was using the section* macro in a way that was incompatible with that package. This seems to work now, with a manually formatted toc heading.



                documentclass{article}
                usepackage{multicol}

                usepackage{titlesec}
                titlespacing{section}{0pt}{4ex}{-0.5parskip}
                titleformat{section}[hang]{raggedrightnormalfontlargebfseries}{thesection.}{1ex}{}

                usepackage{titletoc}
                titlecontents{section} [0pt] { } {thecontentslabel.enspace} { } {leadershbox to 1em{hss.hss}hfill thecontentspage}

                makeatletter
                renewcommandtableofcontents{%
                @starttoc{toc}%
                }
                makeatother
                makeatletter
                renewcommandtableofcontents{%
                @starttoc{toc}%
                }
                makeatother

                begin{document}

                begin{center}
                Large
                textbf{Contents}
                end{center}

                begin{multicols}{2}

                tableofcontents
                newpage

                section{Section 1}
                section{Section 2}
                section{Section 3}
                section{Section 4}
                section{Section 5}
                section{Section 6}
                section{Section 7}
                section{Section 8}
                section{Section 9}
                section{Section 10}
                section{Section 11}
                section{Section 12}
                section{Section 13}
                section{Section 14}
                section{Section 15}
                section{Section 16}
                section{Section 17}
                section{Section 18}
                section{Section 19}
                section{Section 20}
                section{Section 21}
                section{Section 22}
                section{Section 23}
                section{Section 24}
                section{Section 25}
                section{Section 26}
                section{Section 27}
                section{Section 28}
                section{Section 29}
                end{multicols}


                end{document}


                LaTeX output







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 13 '17 at 12:35









                Community

                1




                1










                answered Dec 22 '15 at 17:49









                Tyler

                2,0981127




                2,0981127






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f284334%2fcentred-contents-in-toc-in-twocolumn-document-with-custom-sections%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

                    Contact image not getting when fetch all contact list from iPhone by CNContact

                    count number of partitions of a set with n elements into k subsets

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks