GeneralPartial ToC for Chapters with fancy Headings

LaTeX specific issues not fitting into one of the other forums of this category.
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

Hi all,

I'm working on my PhD thesis and I have a problem with minitoc and fncychap ("Conny" style) packages. Following a minimum example that gene.ate the error:

Code: Select all

\documentclass{book}
\usepackage[Conny]{fncychap}
\usepackage{minitoc}

\begin{document}

\dominitoc
\tableofcontents

\chapter{bla}
\minitoc

\section{blubb}

\section{foo}

\end{document}
And the error from my log file:

Code: Select all

(minitoc) PREPARING MINITOCS FROM test.toc on input line 9.
! Use of \@icentercr doesn't match its definition.
<argument> \def
l.9 \tableofcontents
If you say, e.g., `\def\a1{...}', then you must always
put `1' after `\a', since control sequence names are
made up of letters only. The macro here has not been
followed by the required stuff, so I'm ignoring it.
I noticed that not all fncychap styles generate the error (e.g. no errors with Peters' Lenny style). I work with MacTeX on a Snow Leopard system. Find attached the complete log file.

Anybody can help me?
Thank you

Giorgio
Attachments
test.log
(11.51 KiB) Downloaded 305 times

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Partial ToC for Chapters with fancy Headings

Post by localghost »

Seems to be an incompatibility between the two packages with this chapter style. And it's not the only one which causes trouble. Would using other packages be an option for you?


Best regards and welcome to the board
Thorsten
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

Hi Thorsten and thank you for your reply.

I confirm that the error is generated also with TeX Live 2009 on an Ubuntu system. Probably you are right: this sound as an incompatibility between the two packages. However the error is generated only with some fncychap stiles and this sounds strange. Furthermore about two years ago, for my master thesis, I used both packages with no errors. Unfortunately I can't remember which packages version I used and I'm not expert enough to investigate on the problem in deep. I'd like to notify this issue to the minitoc maintainer, but it seems he is inactive (source: CTAN).

I would use some other packages, but unfortunately I couldn't find any alternatives to those packages (and I really like the Conny style!). Can you suggest me some alternatives?

Thank you and best regards,
Giorgio
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Partial ToC for Chapters with fancy Headings

Post by localghost »

gioboske wrote:[…] Furthermore about two years ago, for my master thesis, I used both packages with no errors. […]
Most LaTeX packages are under steady development (but some not). So problems like this can occur. Minor changes can cause major trouble. But since I'm personally not a TeX expert, I'm not able to spot the source of the error.
gioboske wrote:[…] I would use some other packages, but unfortunately I couldn't find any alternatives to minitoc and fncychap packages (and I really like fncychap Conny style!). Can you suggest me some alternatives? […]
That's exactly the reason why I asked. I had already an idea. But some users insist on old habits although they run into trouble. Therefore I was not sure if you are interested in an alternative solution. So, here we go!

The idea is to mimic the "Conny" chapter style and then add the partial ToCs to each chapter. This can be done by the "twins" titlesec and titletoc.
  • titlesec will allow to alter the chapter style itself. We have to distinguish between numbered and unnumbered chapters because ToC, Lof and LoT won't need a partial ToC. The two chapter styles are done like this.

    Code: Select all

    \titleformat{name=\chapter}[display]
    {\normalfont\Large\filcenter\bfseries}
    {\titlerule[4pt]\vspace{2pt}\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
    {1pc}
    {\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
    
    \titleformat{name=\chapter,numberless}[display]
    {\normalfont\Large\filcenter\bfseries}
    {}
    {1pc}
    {\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
    If we wouldn't have a partial ToC, the first definition would be sufficient.
  • titletoc will allow to add the chapter ToC by incorporating it into the new chapter style. Therefore we can use an optional argument for the above \titleformat macro.

    Code: Select all

    \titleformat{name=\chapter}[display]
    {\normalfont\Large\filcenter\bfseries}
    {\titlerule[4pt]\vspace{2pt}\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
    {1pc}
    {\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
    [\normalsize\normalfont\vspace*{2pc}%
    \hbox{\large\bfseries\contentsname}\vspace{6pt}\titlerule\vspace{3pt}
    \startcontents
    \printcontents{l}{1}{\setcounter{tocdepth}{2}}\titlerule]
    
    \titleformat{name=\chapter,numberless}[display]
    {\normalfont\Large\filcenter\bfseries}
    {}
    {1pc}
    {\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
    Now the differences between numbered and unnumbered chapters are clearer. The commands \startcontents and \printcontents come from titletoc.
All this packed into a complete document together with some dummy text to create some chapters with their content looks like this.

Code: Select all

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[explicit]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}  % drop in actual document

\titleformat{name=\chapter}[display]
{\normalfont\Large\filcenter\bfseries}
{\titlerule[4pt]\vspace{2pt}\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
[\normalsize\normalfont\vspace*{2pc}%
\hbox{\large\bfseries\contentsname}\vspace{6pt}\titlerule\vspace{3pt}
\startcontents
\printcontents{l}{1}{\setcounter{tocdepth}{2}}\titlerule]

\titleformat{name=\chapter,numberless}[display]
{\normalfont\Large\filcenter\bfseries}
{}
{1pc}
{\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}


\begin{document}
  \tableofcontents

  \blinddocument  % drop in actual document
  \blinddocument  % drop in actual document
\end{document}
I've tried to mimic the format of the partial ToC as minitoc would do it. regarding the indentation on both sides I was not successful because I couldn't find the corresponding options. Perhaps this could be an interesting feature suggestion for titletoc.


Remarks:
  • In case that a fancy page style (header and footer) is desired, this can (and in this case should) also be done with titlesec.
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

I tried to copy and paste your code in my old (master thesis) preamble, that loads many other packages and everything works great! Your code really emulates the Conny chapter style!

Now I have just to customize your code to use titlesec instead of fancyhdr also for headers and footers.

It's a pity that the current versions of minitoc and fncychap don't work correctly, since they are really easy to use.

Thank you so much!
Giorgio
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Partial ToC for Chapters with fancy Headings

Post by localghost »

gioboske wrote:[…] Now I have just to customize your code to use titlesec instead of fancyhdr also for headers and footers. […]
If you present the fancyhdr settings for your document we might be able to port them to titlesec.
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

Following the fancyhdr settings for my document (quite simple, I think):

Code: Select all

\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyhead[RO]{\nouppercase{\emph{\rightmark}}}
\fancyhead[LE]{\nouppercase{\emph{\leftmark}}}
\fancypagestyle{plain}{%
  \fancyhf{}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}
\setlength{\headheight}{14.5pt}
Thanks again,
Giorgio
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Partial ToC for Chapters with fancy Headings

Post by localghost »

I'd suggest something like this. The page styles front and back make sure that unnumbered chapters (ToC, LoF, LoT) get the correct header in case they have more than one page.

Code: Select all

\documentclass[11pt]{book}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage[explicit,pagestyles]{titlesec}
\usepackage{titletoc}
\usepackage{blindtext}  % drop in actual document

\titleformat{name=\chapter}[display]
{\normalfont\Large\filcenter\bfseries}
{\titlerule[4pt]\vspace{2pt}\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}
[\normalsize\normalfont\vspace*{2pc}%
\hbox{\large\bfseries\contentsname}\vspace{6pt}\titlerule\vspace{3pt}
\startcontents
\printcontents{l}{1}{\setcounter{tocdepth}{2}}\titlerule]

\titleformat{name=\chapter,numberless}[display]
{\normalfont\Large\filcenter\bfseries}
{}
{1pc}
{\titlerule[2pt]\vspace{1pc}\LARGE\MakeUppercase{#1}}

\newpagestyle{front}[\normalfont]{%
  \sethead[\itshape\chaptertitle][][]{}{}{\itshape\chaptertitle}
  \setfoot[][\thepage][]{}{\thepage}{}
  \headrule
}
\newpagestyle{main}[\normalfont]{%
  \sethead[\itshape\thesection\enspace\sectiontitle][][]{}{}{\itshape\thechapter\enspace\chaptertitle}
  \setfoot[][\thepage][]{}{\thepage}{}
  \headrule
}
\newpagestyle{back}[\normalfont]{%
  \sethead[\itshape\chaptertitle][][]{}{}{\itshape\chaptertitle}
  \setfoot[][\thepage][]{}{\thepage}{}
  \headrule
}
\renewpagestyle{plain}{%
  \sethead[][][]{}{}{}
  \setfoot[][][]{}{}{}
}

\begin{document}
  \frontmatter
  \pagestyle{front}
  \tableofcontents

  \mainmatter
  \pagestyle{main}
  \blinddocument  % drop in actual document
  \blinddocument  % drop in actual document

  \backmatter
  \pagestyle{back}
\end{document}
The commands \frontmatter, \mainmatter and \backmatter are optional to divide a book into the corresponding parts.


Remarks:
  • The part for page styles has been split some time ago to titleps which is now an independent package. The pagestyles option for titlesec loads this package automatically.
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

localghost wrote:I'd suggest something like this. The page styles front and back make sure that unnumbered chapters (ToC, LoF, LoT) get the correct header in case they have more than one page.
I tested your code: once again it works great and I understand that titlesec and titletoc are two very powerful packages (more powerful than the simpler fncyhdr package).
localghost wrote:[...] The commands \frontmatter, \mainmatter and \backmatter are optional to divide a book into the the corresponding parts.
Yes, I used this commands following the suggestion of Lapo Mori tutorial "Writing a thesis with LaTeX".

Thank you for your suggestions and your code!
Giorgio
gioboske
Posts: 8
Joined: Wed Sep 11, 2013 5:06 pm

Partial ToC for Chapters with fancy Headings

Post by gioboske »

Hi Thorsten,

following fncychap documentation, I made some minor changes to your code to better mimic (I hope) the original "Conny" style:

Code: Select all

\titleformat{name=\chapter}[display]
{\normalfont\Huge\filcenter\rm}
{\titlerule[4pt]\vspace{2pt}\titlerule[2pt]\vspace{1pc}\Huge\bfseries\MakeUppercase{\chaptertitlename} \thechapter}
{1pc}
{\titlerule[2pt]\vspace{1pc}\MakeUppercase{#1}}
[\normalsize\normalfont\vspace*{2pc}%
\hbox{\large\bfseries\contentsname}\vspace{6pt}\titlerule\vspace{3pt}
\startcontents
\printcontents{l}{1}{\setcounter{tocdepth}{2}}\titlerule]

\titleformat{name=\chapter,numberless}[display]
{\normalfont\Huge\filcenter\rm}
{}
{1pc}
{\titlerule[2pt]\vspace{1pc}\MakeUppercase{#1}}
What do you think about it?

Finally a question: what are your suggestions if I have to deal with a numbered chapter, but I don't want a partial toc? Just for my curiosity, I don't think it will be necessary for my thesis...

Thanks,
Giorgio
Post Reply