Page LayoutProblem with titlesec / toc on chapter starting page

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Problem with titlesec / toc on chapter starting page

Post by Montag »

Hello,

on each page on which a new chapter starts, I'd like to have a table of contens that lists the section, subsections and subsubsections of this particular chapter. It should look like the "usual boring" table of contens that LaTeX produces by default via \tableofcontens when neither titlesec nor titletoc are loaded. The attached tex-file is as far as I got with the help of the documention for titlesec.
Could someone help me, please? :)
Attachments
titlesec-test.tex
(2 KiB) Downloaded 338 times
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

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

Problem with titlesec / toc on chapter starting page

Post by gmedina »

Hi, enrico

I would remove the \startcontents and \printcontents commands from the \titleformat command for chapters and simply use them after each \chapter command in body of the document, as the following example suggests:

Code: Select all

\documentclass[
11pt,
german,
a4paper
]{scrreprt}

\usepackage[T1]{fontenc}

\usepackage{lipsum,lmodern}

\usepackage[
%headsepline,
automark
]{scrpage2}
\clearscrheadfoot
\setkomafont{pageheadfoot}{\small}
\pagestyle{scrheadings}
\lehead{\pagemark}
\cehead{\leftmark}
\rehead{~}
%	\lefoot{~}
%	\cefoot{\pagemark/\pageref{LastPage}}
%	\refoot{~}
%**********************************************	
\lohead{~}
\cohead{\rightmark}
\rohead{\pagemark}
%	\lofoot{~}
%	\cofoot{\pagemark/\pageref{LastPage}}
%	\rofoot{~}

\renewcommand{\indexpagestyle}{scrheadings}
\renewcommand{\chapterpagestyle}{plain}

\usepackage{titlesec}

%\titleformat{command}
%[shape]
%{format}
%{label}
%{sep}
%{before}
%[after]
\titleformat{\chapter}
{\titlerule\rmfamily\normalfont\scshape\huge}
{\thechapter}
{.5em}
{}
[\vspace*{4pc}]

\titleformat{\section}
{\rmfamily\normalfont\LARGE}
{\thesection}
{.5em}
{}

\titleformat{\subsection}
{\rmfamily\normalfont\large}
{\thesubsection}
{.5em}
{}

\titleformat{\subsubsection}
{\rmfamily\normalfont}
{\thesubsubsection}
{.5em}
{}

\newcommand{\xquad}{\hspace{1em plus.4em minus.4em}}
\usepackage{titletoc}

\begin{document}
\begin{center}
	the title: \Large\textsc{Test Document}
\end{center}
\vspace{5cm}
\begin{center}
	my name - the author
\end{center}
\clearpage
\tableofcontents

\chapter{test1}

\startcontents
\printcontents{0}{1}{\setcounter{tocdepth}{3}\setcounter{secnumdepth}{3}}

\section{subtest1}

\subsection{938he}

\lipsum[2]

\subsection{iiii9999}

\subsubsection{A test subsubsection}

\lipsum[1]

\section{subtest2}

\lipsum[1-3]

\chapter{Another Chapter}
\startcontents
\printcontents{0}{1}{\setcounter{tocdepth}{3}\setcounter{secnumdepth}{3}}

\section{Some section1}

\lipsum[1]

\section{Next section}

\lipsum[3]

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: Problem with titlesec / toc on chapter starting page

Post by Montag »

Thank you, but that doesn't work correctly. I tried it myself before, in a way, but I c&p your code and it yields the same wrong result.
It gives me the "usual boring" table of contents of the whole document plus an error. Well, at least not about 40 errors like I had before...

It's truly annoying. I don't understand it at all. Maybe there will be another solution/hint given by someone else. I'd appreciate it a lot. :)
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with titlesec / toc on chapter starting page

Post by gmedina »

enrico wrote:T...
It gives me the "usual boring" table of contents of the whole document plus an error. Well, at least not about 40 errors like I had before...
Perhaps your system is outdated; I get no errors with the code I provided, and I get each chapter with its own table of contents that includes only the sections, subsections and subsubsections (see the attached PDF) corresponding to each chapter.

Here's the file list used by my system (taken from the .log file after addition of \listfiles in my previous code) after compilation of my previous code; compare with your list, and update your system if required:

Code: Select all

 *File List*
scrreprt.cls    2010/06/17 v3.06 KOMA-Script document class (report)
scrkbase.sty    2010/06/17 v3.06 KOMA-Script package (KOMA-Script-dependent bas
ics and keyval usage)
 scrbase.sty    2010/06/17 v3.06 KOMA-Script package (KOMA-Script-independent b
asics and keyval usage)
  keyval.sty    1999/03/16 v1.13 key=value parser (DPC)
scrlfile.sty    2009/03/25 v3.03 KOMA-Script package (loading files)
tocbasic.sty    2010/06/09 v3.06 KOMA-Script package (handling toc-files)
scrsize11pt.clo    2010/06/17 v3.06 KOMA-Script font size class option (11pt)
typearea.sty    2010/06/17 v3.06 KOMA-Script package (type area)
 fontenc.sty
   t1enc.def    2005/09/27 v1.99g Standard LaTeX file
  lipsum.sty    2005/01/26 v1.0 150 paragraphs of Lorem Ipsum dummy text
 lmodern.sty    2009/10/30 v1.6 Latin Modern Fonts
scrpage2.sty    2010/04/22 v2.5 LaTeX2e KOMA-Script package
titlesec.sty    2007/08/12 v2.8 Sectioning titles
titletoc.sty    2007/08/12 v1.6 TOC entries
   t1lmr.fd    2009/10/30 v1.6 Font defs for Latin Modern
  ot1lmr.fd    2009/10/30 v1.6 Font defs for Latin Modern
  omllmm.fd    2009/10/30 v1.6 Font defs for Latin Modern
 omslmsy.fd    2009/10/30 v1.6 Font defs for Latin Modern
 omxlmex.fd    2009/10/30 v1.6 Font defs for Latin Modern
  t1lmss.fd    2009/10/30 v1.6 Font defs for Latin Modern
 ***********
Attachments
titlesec-test.pdf
(123.87 KiB) Downloaded 316 times
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: Problem with titlesec / toc on chapter starting page

Post by Montag »

Thank you for your reply.

Ah ... yes, now I see. You removed the command(s) which are based on the titletoc package, \titlecontents.
Well, you see, I'd like very much to keep them, meaning I would a) have my own customized headings and b) get one little toc at the beginning of the document (only chapters and section, maybe even parts) and a detailed toc on the first page of a new chapter (this one with sections, subsections and subsubsections). :)

Just for clarification, I've just figured what I wrote about, I guess it does not have anything to do with the date of the packages...
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with titlesec / toc on chapter starting page

Post by gmedina »

enrico wrote:...Ah ... yes, now I see. You removed the command(s) which are based on the titletoc package, \titlecontents.
Well, you see, I'd like very much to keep them, meaning I would a) have my own customized headings and b) get one little toc at the beginning of the document (only chapters and section, maybe even parts) and a detailed toc on the first page of a new chapter (this one with sections, subsections and subsubsections). :)
The headings won't be affected by the \titlecontents commands... perhaps you are referring to the entries of the table of contents? As for b), simply add

Code: Select all

\setcounter{tocdepth}{1}
to the preamble of my code.

Quite frankly I don't understand your reply. The example I gave you satisfies these requirements (after completion with the line I just mentioned), so I still don't see what's going wrong.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Problem with titlesec / toc on chapter starting page

Post by Montag »

You are right, sorry for giving such a confusing answer.
gmedina wrote: ... perhaps you are referring to the entries of the table of contents?
Yes, exactly! That's why in my inital posting there was

Code: Select all

\usepackage{titletoc}

\contentsmargin{0pt}
\titlecontents{chapter}[0pt]
    {\addvspace{2pc}\large}
    {\rmfamily\scshape\thecontentslabel~}
    {}
    {~-~\thecontentspage}
    [\vspace{2pt}]
\titlecontents*{section}[1.5pc]
    {\small}
    {\thecontentslabel~}
    {}
    {~-~\thecontentspage}
    [\xquad\textbullet\xquad]
    \setcounter{tocdepth}{1}
\contentsfinish
. :) This gives me the toc at the beginning of the whole document.

So the following quote is, in a sense, already applied.
As for b), simply add

Code: Select all

\setcounter{tocdepth}{1}
to the preamble of my code.
But it is enhanced by titletoc's commands. As you can see in the code I posted above. So the requirement includes the style.

Obviously, the difficult thing for me is how to get a proper "boring" detailed toc on a first page of a new chapter.
The problem is: LaTeX still applies some the new style (which I used for the toc at the beginning of the whole document) to said "detailed" toc on a first page of a chapter. In a way, I can understand the conflict, but then again in another way, I can't figure out why it does that.

I also seem to have a problem with

Code: Select all

\printcontents{0}{1}{\setcounter{tocdepth}{3}\setcounter{secnumdepth}{3}}
in my original document, there's always an error about a missing \item. And that I can't figure out either. It's just more text in between, some math and another chapter, but the code I just wrote does not work there. :?: :(
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: Problem with titlesec / toc on chapter starting page

Post by Montag »

Another version finally: I figured out some stuff, especially how to work with the "prefix"-option, but apparently I still got something wrong. I'd like the partial TOC at the beginning of chapter 1 to be formatted like the usual TOC that LaTeX produces by default via \tableofcontents, without titlesec or any other package.
Could anyone give me a hint?
Attachments
titlesec-test.pdf
(110.4 KiB) Downloaded 383 times
titlesec-test.tex
(3.3 KiB) Downloaded 369 times
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
Post Reply