25

my goal is to get new style of Table of Contents, new style of Chapter and new style of section. I there is one more: how to change itemize native symbol for a black square?

Table of Contents: text on the left side in the middle of two lines. And there is a big white space non normal one. enter image description here

Chapter: number of chapter in a roman in a black box on the line above the chapter name, Name of chapter on right side, another line under name of Chapter

enter image description here

Section: I want to add a black square at the begining of each section name. enter image description here I appreciate that thank You

3
  • 1
    With respect to the section formatting, you want to add a black square at the beginning (before the title), but should this square replace the section number or do you want to keeo the numbering? Commented Aug 10, 2012 at 1:47
  • 1
    Should the elements (the chapter titles, the entries in the ToC) be boldfaced or not? Commented Aug 10, 2012 at 2:03
  • I want to have a section number. In table of contents the chapters should be boldfaced, but section no. In text both should by blodfaced. Commented Aug 10, 2012 at 11:09

1 Answer 1

32
+50

You can use the packages titlesec for the titles of the sectional units, and titletoc for the entries in the ToC; a little example producing the layout for chapters and sections, and the redefinition of the label for itemize to use a square (feel free to adjust the settings according to your needs):

\documentclass{book}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage[dotinlabels]{titletoc}

% chapter tiltes formatting
\titleformat{\chapter}[display]
  {\normalfont\sffamily\bfseries\LARGE}
  {\renewcommand{\thechapter}{\Roman{chapter}}\hspace*{0.5em}\colorbox{black}{%
    \parbox[c][1.2cm][c]{1cm}{%
      \centering\textcolor{white}  {\Huge\thechapter}}}}
  {-1ex}
  {\titlerule\vspace{.7ex}\filleft\MakeUppercase{#1}}
  [\vspace{.2ex}\titlerule]
% chapter tiltes spacing
\titlespacing*{\chapter}{0pt}{50pt}{80pt}

% section tiltes formatting
\titleformat{\section}
  {\normalfont\Large\bfseries}{\MySecSquare\ \thesection}{1em}{#1}
\titleformat{name=\section,numberless}
  {\normalfont\Large\bfseries}{\MySecSquare}{1em}{#1}

% formatting for chapter entries in ToC  
\titlecontents{chapter}
  [1.5em]{}
  {\sffamily\bfseries\contentslabel{1.5em}}
  {\hspace*{-1.5em}}
  {\hfill\sffamily\bfseries\contentspage}
% formatting for section entries in ToC  
\titlecontents{section}
  [3.8em]{}
  {\sffamily\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {\titlerule*[1pc]{.}\sffamily\contentspage}

% Square to be used in itemize
\newcommand\MySquare{%
  \leavevmode\hbox to 1.2ex{\hss\vrule height .9ex width .7ex depth -.2ex\hss}}
% Square to be used in section titles
\newcommand\MySecSquare{%
  \leavevmode\hbox to 1.2ex{\hss\vrule height 1.3ex width 1.1ex depth -.2ex\hss}}

% First level of itemize uses a square
\renewcommand\labelitemi{\MySquare}

\begin{document}

\tableofcontents

\chapter{Test Chapter One}
\section{Test Section One One}
\begin{itemize}
\item First item.
\item Second item.
\item Third item.
\end{itemize}
\section{Test Section One Two}
\chapter{Test Chapter Two}
\chapter{Test Chapter Three}

\end{document}

An image of the ToC showing the requested formatting for the entries, and an image of the first numbered chapter, showing the desired chapter titles formatting, the use of a black square in itemize and the section titles formatting:

enter image description here

enter image description here

There's a little detail that deserves some thought: the black box used to typeset the chapter number; in the code above I used a \parbox of fixed width (I chose 1cm) and this will be insufficient for "large" roman numerals (such as VIII), One option is to increase the width of the \parbox, but then small numerals (such as I) might not look good inside a too wide box. Another option is to have a default width of, say 1cm, and let the widht of the \parbox increase just for those numbers requiring more spacing; here's now the code implementing this idea:

\documentclass{book}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\usepackage[dotinlabels]{titletoc}

\newlength\BoxWd
\setlength\BoxWd{1cm}
\newlength\Aux

% chapter tiltes formatting
\titleformat{\chapter}[display]
  {\normalfont\sffamily\bfseries\LARGE}
  {\renewcommand{\thechapter}{\Roman{chapter}}%
    \settowidth\Aux{\textcolor{white}{\Huge\thechapter}}
    \ifnum\Aux>\BoxWd
      \setlength\BoxWd{\Aux}
    \else\fi
    \hspace*{0.5em}\colorbox{black}{%
    \parbox[c][1.2cm][c]{\BoxWd}{%
      \centering\textcolor{white}{\Huge\thechapter}}}}
  {-1ex}
  {\titlerule\vspace{.7ex}\filleft\MakeUppercase{#1}}
  [\vspace{.2ex}\titlerule]
% chapter tiltes spacing
\titlespacing*{\chapter}{0pt}{50pt}{80pt}

% section tiltes formatting
\titleformat{\section}
  {\normalfont\Large\bfseries}{\MySecSquare\ \thesection}{1em}{#1}

% formatting for chapter entries in ToC  
\titlecontents{chapter}
  [1.5em]{}
  {\sffamily\bfseries\contentslabel{1.5em}}
  {\hspace*{-1.5em}}
  {\hfill\sffamily\bfseries\contentspage}
% formatting for section entries in ToC  
\titlecontents{section}
  [3.8em]{}
  {\sffamily\contentslabel{2.3em}}
  {\hspace*{-2.3em}}
  {\titlerule*[1pc]{.}\sffamily\contentspage}

% Square to be used in itemize
\newcommand\MySquare{%
  \leavevmode\hbox to 1.2ex{\hss\vrule height .9ex width .7ex depth -.2ex\hss}}
% Square to be used in section titles
\newcommand\MySecSquare{%
  \leavevmode\hbox to 1.2ex{\hss\vrule height 1.3ex width 1.1ex depth -.2ex\hss}}

% First level of itemize uses a square
\renewcommand\labelitemi{\MySquare}

\begin{document}

\tableofcontents

\chapter{Test Chapter One}
\setcounter{chapter}{17}% just for the example
\chapter{Test Chapter Eighteen}

\end{document}

An image of the titles for chapters I and XVIII:

enter image description here

enter image description here

11
  • WOW! I love it. There is only one thing: How to do a big skip between Contents and Chapter included in Contents, as it is showed on the first picture. Commented Aug 10, 2012 at 11:05
  • 1
    @DanielMiliński right now I am busy, but in a few hours I will update my answer with the (easy) modifications requested. In the meantime I have two questions 1) The vertical skip between the title and the text should only apply to the Table of Contents or should it apply to all chapters? 2) You said that the itemize doesn't work as you expected, but you requested a square and my code produces a square... can you please explain in detail what is not working? Commented Aug 10, 2012 at 13:10
  • 1
    @DanielMiliński You're welcome! I'm glad I could help. I've updated my answer introducing some modifications; in particular, the ToC entries and the spacing after chapter are now incorporated; I also included a new approach to redefine the symbol used in itemize (this new approach doen't require additional packages and should work). Please let me know if this is what you wanted. Commented Aug 10, 2012 at 17:54
  • 1
    @DanielMiliński I corrected the position of the square in sections. I also added a new variation automatically modifying the width of the black box used for the chapter numbers. Commented Aug 11, 2012 at 2:50
  • 1
    @DanielMiliński I just added to my example the code for unnumbered sections to also have the black square. Regarding your other requirements, I think it's best to open a new question with them; you could add a link to this question so that people would know that it is a follow-up question. Commented Aug 12, 2012 at 2:11

You must log in to answer this question.

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