Text Formattingtitlesec | Prefix for Section Heading

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
Amazon
Posts: 9
Joined: Sun May 13, 2012 5:06 pm

titlesec | Prefix for Section Heading

Post by Amazon »

I'm writing a document where I have until now used \section for defining 'chapters' of my document.

I would like the output to be "Section 1, (Title)" instead of "1 (Title)" which is the default for \section. Also the ToC should display in the same way, "Chapter 1, (Title)". Lower headings levels should not be affected.

I have heard that using titlesec is a way to accomplish this, but I haven't been successful yet. Please help me. :)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

titlesec | Prefix for Section Heading

Post by Stefan Kottwitz »

Hi,
Amazon wrote:I have heard that using titlesec is a way to accomplish this
that's correct!
Amazon wrote:but I haven't been successful yet
Did you already read the titlesec documentation? What did you try?

Stefan
LaTeX.org admin
User avatar
Amazon
Posts: 9
Joined: Sun May 13, 2012 5:06 pm

Re: titlesec | Prefix for Section Heading

Post by Amazon »

Yes I've read the documentation, I find it very poor. The manual does a bad job at explaining the different parts and their function of the commands. I have tried to even do a simple thing like just adding a dot after the section number without luck.

By the way I think that titlesec alone won't affect the ToC? Is titletoc needed?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

titlesec | Prefix for Section Heading

Post by Stefan Kottwitz »

For the TOC, I know that tocloft does a good job and that it's easy to insert Chapter into the TOC entries.

I think the mentioned documentation of titlesec is especially good because it provides the commands for the standard headings layout in its appendix. So it's really easy to make small changes - copy and paste the code lines from the appendix and modify slightly. Did you see this appendix?

Stefan
LaTeX.org admin
User avatar
Amazon
Posts: 9
Joined: Sun May 13, 2012 5:06 pm

titlesec | Prefix for Section Heading

Post by Amazon »

Ok, I've almost done it. The only issue is that the "label" isn't the same size as it should be.

the code:

Code: Select all

\titleformat{\section}{\bfseries}{Section \thesection, }{0em}{}
result: (left: before, right: after)
section-format.png
section-format.png (4.97 KiB) Viewed 9206 times
How do I make it appear in the correct size?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

titlesec | Prefix for Section Heading

Post by localghost »

As the titlesec manual describes in Section 9.2 for the default formatting of the headings in the standard classes, you should add \Large as one command to change font sizes.

Code: Select all

\titleformat{\section}{\normalfont\Large\bfseries}{Section \thesection,}{1em}{}

Thorsten
User avatar
Amazon
Posts: 9
Joined: Sun May 13, 2012 5:06 pm

Re: titlesec | Prefix for Section Heading

Post by Amazon »

Thank you Thorsten.
Post Reply