Generaltitlesec | Custom Headings

LaTeX specific issues not fitting into one of the other forums of this category.
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

titlesec | Custom Headings

Post by epicurea »

I am trying to build 2 new custom headings using titlesec as under:

Code: Select all

\titleclass{\WP}{straight}[\section]
\titleformat{\WP}[hang]{\normalfont\scshape}
	{\S\,Work Package\,\oldstylenums{\theWP}.}{.5em}{}[]
\titlespacing{\WP}{0pt}{*1.5}{*0}
\newcounter{WP}
%\renewcommand\theWP{\thesection.\arabic{WP}}
\renewcommand\theWP{\arabic{WP}}

\titleclass{\Taskr}{straight}[\WP]
\titleformat{\Taskr}[hang]{\normalfont}
	{Bingo\,\arabic{\theTaskr}.}{.5em}{}[]
\titlespacing{\Taskr}{0pt}{*1.5}{*0}
\newcounter{Taskr}
%\renewcommand\theTaskr{\theWP.\arabic{Taskr}}
\renewcommand\theTaskr{\arabic{Taskr}}
When I call \WP, everything works fine, but when I call \Taskr I get:

Code: Select all

./PROCESS_C.tex:180:Missing number, treated as zero. \Taskr {test}
What am I doing wrong??
Thanks!

Recommended reading 2024:

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

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

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

titlesec | Custom Headings

Post by gmedina »

The problem is in this line:

Code: Select all

{Bingo\,\arabic{\theTaskr}.}{.5em}{}[]
Change it to

Code: Select all

{Bingo\,\arabic{Taskr}.}{.5em}{}[]
1,1,2,3,5,8,13,21,34,55,89,144,233,...
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

Re: titlesec | Custom Headings

Post by epicurea »

That works - fantastic and many thanks!
Could you explain why that works though? How come it is fine for the 1st set of declarations but not the second?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

titlesec | Custom Headings

Post by gmedina »

Sure. I assume you are talking about the difference between the use of \oldstylenums and \arabic.

Some commands, such as \arabic, \roman, etc, expect as their argument a counter. Here you can find some information about counters.

On the other hand the argument of \oldstylenums has to be the set of digits (or, in your case, the actual numerical representation of the counter that you defined) that you want to type in that style.

The command \the produces the visual representation for a counter. In the link I provided you can find additional information.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

Re: titlesec | Custom Headings

Post by epicurea »

I see, so it has to do with the counter formatting I was choosing.
That was very helpful - many thanks!
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

titlesec | Custom Headings

Post by epicurea »

Hi - One more problem. So I formatted my second declaration like so:

Code: Select all

\newcounter{Taskr}
\renewcommand\theTaskr{\theWP.\arabic{Taskr}}
\titleclass{\Taskr}{straight}[\WP]
\titleformat{\Taskr}[runin]{\normalfont\em}
	{\emph{Task\,\theTaskr}}{.5em}{}[:\,]
\titlespacing{\Taskr}{0pt}{*0}{*0}
Now, when the second \WP is called (which is the heading one level above \Taskr) it continues the numbering for \Taskr from where the previous set left off. The output looks like this:

WP 1. Here is the first
Task 1.1 Some text here
Task 1.2 Some more text here
WP 2. Now the second
Task 2.3 Here is where it should start from 1 again
Task 2.4 And so on

Why isn't the counter reset? I have specified in the titleclass declaration that \Taskr is a child of \WP, so I assumed this would take care of it.

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

titlesec | Custom Headings

Post by gmedina »

Two possibilities:
1)

Code: Select all

\usepackage{amsmath}
\numberwithin{Taskr}{WP}
2)

Code: Select all

\usepackage{chngcntr}
\counterwithin{Taskr}{WP}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

Re: titlesec | Custom Headings

Post by epicurea »

That works!
Thanks - you have been most helpful.
epicurea
Posts: 11
Joined: Mon May 12, 2008 8:11 pm

titlesec | Custom Headings

Post by epicurea »

This is turning into a very interesting exercise!
Everything works fine except that while defining the new headings (WP, Taskr) I did not plan for the fact that I only wanted these as alternatives to the \subsection and \subsubsection commands and not as replacements. Naturally, this results in no numbering for \subsection etc in other parts of the document where I no longer require \WP and \Taskr. Do you know of a good workaround to this?
Thanks!
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

titlesec | Custom Headings

Post by gmedina »

You will have to increase the value of the counter secnumdepth. In the preamble, use something like

Code: Select all

\setcounter{secnumdepth}{5}
ans analogously, for the subsections to be included in the ToC you will have to inclrease tocdepth:

Code: Select all

\setcounter{tocdepth}{5}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply