6

I'm having a problem with the chapter headings formatting. I would like to change only the first letter of each chapter, but for the lists of figures and tables chapters it's not working.

Here is the example:

Generated pdf

\documentclass[oneside]{book}

\font\chapterTextFont = Rothdn scaled 4500 \relax
\def\splitfirstchar#1#2\sentinel{
  \chapterTextFont\uppercase{#1}\LARGE\uppercase{#2}}
\def\chapterText#1{\splitfirstchar#1\sentinel}


\usepackage{titlesec}
\titleformat{\chapter}
  {\normalfont\LARGE\bfseries}{}{1em}{\chapterText}


\begin{document}

\listoffigures
\begingroup
\let\clearpage\relax
\chapter{Testing title}
\endgroup

\end{document}

Might be possible to fix this problem by removing the text formatting of \listfigurename and save in another variable, but I do not know how to do this.

========= Edit 2013/01/19 ========

Simplest solution found by Ulrike Fischer (Thank you!)

Just change:

\def\chapterText#1{\splitfirstchar#1\sentinel}

to:

\def\chapterText#1{\expandafter\splitfirstchar#1\sentinel}

And also thank you Gonzalo Medina and karlkoeller both answers worked too.

2
  • 2
    Put \expandafter before the \splitfirstchar in \chapterText Commented Jan 16, 2014 at 17:51
  • @UlrikeFischer Can you please make it an answer? It is by far the best solution... Commented Jan 18, 2014 at 17:54

2 Answers 2

4

It's an expansion problem. Without explicitly rewriting \listfigurename (and other predefined names such as \listtablename), you can do

\documentclass[oneside]{book}
\usepackage{etoolbox}

\font\chapterTextFont = Rothdn scaled 4500 \relax
\expandafter\def\expandafter\splitfirstchar#1#2\sentinel{
  \chapterTextFont\expandafter\uppercase{#1}\LARGE\uppercase{#2}}
\def\chapterText#1{\splitfirstchar#1\sentinel}

\patchcmd{\listoffigures}{\chapter*{\listfigurename}}{\chapter*{\expandafter\expandafter\chapterText{\listfigurename}}}{}{}
\patchcmd{\listoftables}{\chapter*{\listtablename}}{\chapter*{\expandafter\expandafter\chapterText\listtablename}}{}{}

\usepackage{titlesec}
\titleformat{\chapter}
  {\normalfont\LARGE\bfseries}{}{1em}{\chapterText}
\titleformat{name=\chapter,numberless}
  {\normalfont\LARGE\bfseries}{}{1em}{}

\begin{document}

\let\cleardoublepage\relax
\listoffigures
\listoftables
\chapter{Testing title}

\end{document}
1
  • 2
    @HarishKumar Hi, Harish. I missed you all too :-) I'll try to be around here a little more, if I can. Commented Jan 17, 2014 at 16:12
6

Add the following lines in your preamble:

\usepackage{etoolbox}
\patchcmd{\listoffigures}
  {\chapter*{\listfigurename}}
  {\chapter*{List of Figures}}
  {}
  {}
\patchcmd{\listoftables}
  {\chapter*{\listtablename}}
  {\chapter*{List of Tables}}
  {}
  {}

In this way we patch \listoffigures and \listoftables so to use the expanded names, and this is the result (I've added \thechapter to \titleformat just in case you wanted, remove it if you don't want it):

enter image description here

Complete code:

\documentclass[oneside]{book}

\font\chapterTextFont = Rothdn scaled 4500 \relax
\def\splitfirstchar#1#2\sentinel{
  \chapterTextFont\uppercase{#1}\LARGE\uppercase{#2}}
\def\chapterText#1{\splitfirstchar#1\sentinel}

\usepackage{titlesec}
\titleformat{\chapter}
  {\normalfont\LARGE\bfseries}{\Huge\thechapter}{1em}{\chapterText}

\usepackage{etoolbox}
\patchcmd{\listoffigures}
  {\chapter*{\listfigurename}}
  {\chapter*{List of Figures}}
  {}
  {}
\patchcmd{\listoftables}
  {\chapter*{\listtablename}}
  {\chapter*{List of Tables}}
  {}
  {}

\begin{document}

\begingroup
\let\clearpage\relax
\listoftables
\listoffigures
\chapter{Testing title}
\endgroup

\end{document} 

You must log in to answer this question.

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