0

I'm trying to create a document that has two different types of headings within each section.

The first heading needs to go in a contents page and is of the form

Block #1 -- #2 (3 Sessions)

where #1 is a number with two decimal places increasing by 0.01 each time (ie in the first section the number is 0.00, the second section the number is 0.01, the third section 0.02 and so on up to 0.42), #2 is just the title.

Underneath this, I need to have a second heading for my Sessions. There are generally 3 Sessions per section, though not always. I have tried to use a counter, though cannot get it working.

I am hopeful that I can use \section for the first heading and a counter for the second heading that automatically numbers the sessions from 1 onwards.

Below is a sample of what a finished document would look like.

Thanks so much, Wendy

%%contents page

Contents

Block 0.00 Introduction (2 sessions)

Block 0.01 Counting to 3 (3 sessions)

Block 0.02 Counting to 6 (3 sessions)

Block 0.03 Counting to 9 (3 sessions)

%%Main document

Block 0.00 Introduction (2 sessions)

Session 1

Blah blah

Session 2

Blah blah

Block 0.01 Counting to 3 (3 sessions)

Session 3

Blah Blah

Session 4

Blah Blah

Session 5

Blah Blah

1
  • The easy solution is to use some;thing like \section and \subsection and modify the \l@section and \l@subsection as desired. If you want two types of divisions with the same depth/level, you can copy the source for \section, modify and rename it and create a correspoind \l@... to print it. Commented Feb 19 at 23:03

1 Answer 1

1

It is a bit unclear what the overall structure of your document is. The following hopefully will give you something to work with and modify to your needs.

  • The following uses \titlesec and \titletoc. Neither packages are necessary, it is just that I am more familiar with them so I use them out of convenience.
  • Most of what you need are simple formatting changes. Only two of your requirements require some work:
    1. The automatic counting of the number of sessions in a block
    2. The formatting of the block number (I assume the 10th block should be 0.10 and not 0.010).
  • The following code implements "Block" as \section and "Session" as \subsection.
\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}

\makeatletter
% Continuous numbering of sessions
\counterwithout{subsection}{section}
% Helper macro to register the first and last sessions in a block, as well as the total number of sessions
\newcommand*\count@sessions[2]{%
        \ifcsname sessions@#1@start\endcsname
        \else
                \expandafter\gdef\csname sessions@#1@start\endcsname{#2}
        \fi
        \expandafter\gdef\csname sessions@#1@end\endcsname{#2}
        \expandafter\xdef\csname sessions@#1@total\endcsname{\the\numexpr #2 + 1 - \csname sessions@#1@start\endcsname\relax}
}
% Helper macro to display to total number of sessions in a block; exists only to use singular (session) if there is only one session. 
\newcommand*\display@total@sessions[1]{%
        \ifcsname sessions@#1@start\endcsname%
                \if\csname sessions@#1@total\endcsname1%
                        (1~session)%
                \else%
                        (\csname sessions@#1@total\endcsname~sessions)%
                \fi
        \fi}
% One can also display the list of sessions, for example
\newcommand*\display@sessions@list[1]{%
        \ifcsname sessions@#1@start\endcsname%
                \if\csname sessions@#1@total\endcsname1%
                        (Session \csname sessions@#1@start\endcsname)%
                \else
                        (Sessions \csname sessions@#1@start\endcsname--\csname sessions@#1@end\endcsname)%
                \fi\fi}
% Pad a number with a zero if less than 10 (no extra checks, assume nonnegative.
\newcommand*\padnum[1]{%
        \ifnum10>#1\relax%
                0#1%
        \else%
                #1%
        \fi
}

%%% Two options below uncomment the first line to display the total number of sessions in a block; uncomment the second line to display 
%%% the list of all sessions in that block
\titleformat{\section}{\bfseries\large}{Block 0.\padnum{\thesection}}{0.5em}{#1 \display@total@sessions{\thesection}}
%\titleformat{\section}{\bfseries\large}{Block 0.\padnum{\thesection}}{0.5em}{#1 \display@sessions@list{\thesection}}
\titleformat{\subsection}{\itshape}{Session \thesubsection}{0pt}{}[\immediate\write\@auxout{\string\count@sessions{\thesection}{\thesubsection}}]

% Finally, format the toc
\titlecontents{section}[0em]{\normalfont}{Block 0.\padnum{\thecontentslabel} }{}{ \display@total@sessions{\thecontentslabel}{\hspace{1ex}\titlerule*[1ex]{.}}\contentspage}
\setcounter{tocdepth}{1}
\makeatother

\begin{document}

\tableofcontents
\section{Introduction}

\subsection{}

\section{Counting to 3}

\subsection{}

\subsection{}

\section{Countering to 6}

\subsection{}

\subsection{}

\subsection{}

\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .