LaTeX forum ⇒ Page Layout"Section 1" instead of "1 Section"

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
sveioen
Posts: 28
Joined: Tue Mar 06, 2007 1:04 am

"Section 1" instead of "1 Section"

Postby sveioen » Tue Jan 20, 2009 12:26 am

Hello all!

I was wondering if anybody know how to change to way sections/subsections etc. are being numbered. I would like to make LaTeX format, say, "\section{Stuff}" into "Stuff 1" instead of "1 Stuff".

Thank you!

corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Postby corderin » Tue Jan 20, 2009 11:51 am

You could have a look at the titlesec package, you are able to change the label format, but I guess with this package you won´t be able to change the order between label (2.1 for example) and title.

;)

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Postby gmedina » Wed Jan 21, 2009 4:07 pm

Using titlesec (as suggested by corderin) does allow to achieve the desired result. Take a look at the following example:
  1. \documentclass{book}
  2. \usepackage[nobottomtitles*]{titlesec}
  3. \usepackage{ifthen}
  4. \usepackage{lipsum}% just to generate some text
  5.  
  6. \titleformat{\section}[runin]
  7. {\normalfont\Large\bfseries}
  8. {}{0pt}{}%
  9. [\ifthenelse{\equal{\thesection}{0}}{\\\vspace*{0pt}}{\space\thesection\\}]
  10.  
  11. \titlespacing{\section}
  12. {0pt}{*2}{0pt}
  13.  
  14. \begin{document}
  15. \tableofcontents
  16.  
  17. \chapter{Dummy chapter}
  18. \section{A test section}
  19. \lipsum[1-2]
  20. \section{Another test section}
  21. \lipsum[1-2]
  22.  
  23. \end{document}

Remark: use with caution; this solution is highly volatile ;)
1,1,2,3,5,8,13,21,34,55,89,144,233,...

sveioen
Posts: 28
Joined: Tue Mar 06, 2007 1:04 am

Postby sveioen » Wed Jan 21, 2009 6:16 pm

Thank you so much for the example, gmedina. This is just what I've been looking for!

corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Postby corderin » Wed Jan 21, 2009 6:35 pm

The only problem I have found with this wonderful code of gmedina are the TOC entries, I have been trying to get the same line as for the section titles using the titletoc package, but it seems a bit difficult.

Maybe gmedina can achieve solve that matter too!

With titletoc you can put some code after the TOC entry, but I have seen it puts this code just rigth after the whole entry, this is, after the page... :?

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Postby gmedina » Wed Jan 21, 2009 7:36 pm

corderin wrote:The only problem I have found with this wonderful code of gmedina are the TOC entries, I have been trying to get the same line as for the section titles using the titletoc package, but it seems a bit difficult.

Maybe gmedina can achieve solve that matter too!...

A possible solution using titletoc:
  1. \documentclass{book}
  2. \usepackage[nobottomtitles*]{titlesec}
  3. \usepackage{titletoc}
  4. \usepackage{ifthen}
  5. \usepackage{lipsum}% just to generate some text
  6.  
  7. \titleformat{\section}[runin]
  8. {\normalfont\Large\bfseries}
  9. {}{0pt}{}%
  10. [\ifthenelse{\equal{\thesection}{0}}{\\\vspace*{0pt}}{\space\thesection\\}]
  11.  
  12. \titlespacing{\section}
  13. {0pt}{*2}{0pt}
  14.  
  15. \titlecontents{section}
  16. [1.5em]
  17. {}{}
  18. {\hspace*{-2.3em}}
  19. {\space\contentslabel{0pt}\hfill\contentspage}
  20.  
  21. \begin{document}
  22. \tableofcontents
  23.  
  24. \chapter{Dummy chapter}
  25. \section{A test section}
  26. \lipsum[1-4]
  27. \section{Another test section}
  28. \lipsum[1-2]
  29.  
  30. \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

corderin
Posts: 77
Joined: Sun Dec 14, 2008 2:27 pm

Postby corderin » Wed Jan 21, 2009 8:17 pm

Gmedina I have been a time trying to solve this and I couldn´t, the result is achieved, and modifiying the last line as follows you get the separation dots between title and page in the TOC!


  1. \titlecontents{section}
  2. [1.5em]
  3. {}{}
  4. {\hspace*{-2.3em}}
  5. {\space\contentslabel{0pt}\titlerule*[1pc]{.}\contentspage}


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 0 guests