Text Formattingcentering a chapter title

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

Re: centering a chapter title

Post by thedoctor818 »

Thanks you so very much - it worked beautifully. I am really getting to appreciate a bit of the intricacies of this program, at least a little. :)

-Michael
-Michael D

Recommended reading 2024:

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

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

thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

centering a chapter title

Post by thedoctor818 »

Sorry to bug you again, but it was working fine; but now I am getting an error:

Code: Select all

\documentclass[12pt,letterpaper,twoside,openany]{book}
\usepackage[pagestyles]{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}

\newpagestyle{mystyle}{\sethead{}{}{}\setfoot{}{\thepage}{}}
\pagestyle{mystyle}

\begin{document}
\maketitle
\tableofcontents

\addcontentsline{toc}{chapter}{WEEKDAY EVENING PRAYERS.}
\chapter*{WEEKDAY EVENING PRAYERS.}
\begin{document}
\maketitle
\tableofcontents

\addcontentsline{toc}{chapter}{WEEKDAY EVENING PRAYERS.}
\chapter*{WEEKDAY EVENING PRAYERS.}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

<more text>

etc

\end{document}
At first, it seemed to work - then when I started typing more, it gave me the following error - even when I reduced it to the above.

Error Line 26 LaTex Error: Two \documentclass or \documentstyle commands.

Error Line 28 LaTex Error: Option clash for package titlesec.

Error line 61: Undefined Conrtol Sequence: \widenhead.

Thanks again.

-MD
-Michael D
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

centering a chapter title

Post by localghost »

Your code contains a duplicate \begin{document} and some more lines right after that. The following code works fine.

Code: Select all

\documentclass[12pt,letterpaper,twoside,openany]{book}
\usepackage[pagestyles]{titlesec}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}
{0pt}{50pt}{40pt}

\newpagestyle{mystyle}{\sethead{}{}{}\setfoot{}{\thepage}{}}
\pagestyle{mystyle}

\begin{document}
%\maketitle
\tableofcontents

\addcontentsline{toc}{chapter}{WEEKDAY EVENING PRAYERS.}
\chapter*{WEEKDAY EVENING PRAYERS.}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

<more text>

etc

\end{document}

Thorsten
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

centering a chapter title

Post by thedoctor818 »

Thanks to all for your help. And thanks to Thorsten for pointing that out re: the code format. I must have accidentaly missed that when I read the rules the other day. Just one more thing: I want to number the chapters in the toc ONLY< but keep them unnumbered in the body text. Is that possible? Here is the code I have thus far.

Code: Select all

\documentclass[12pt,letterpaper,twoside,openany]{book}
\usepackage[pagestyles]{titlesec}

\titleformat{\chapter}[display]
{\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}
{0pt}{50pt}{40pt}

\newpagestyle{mystyle}{\sethead{}{}{}\setfoot{}{\thepage}{}}
\pagestyle{mystyle}

\begin{document}
%\maketitle
\tableofcontents

\addcontentsline{toc}{chapter}{WEEKDAY EVENING PRAYERS.}
\chapter*{WEEKDAY EVENING PRAYERS.}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

<more text>

etc

\appendix
\chapter{ON THE SIGN OF THE PRECIOUS AND LIFE-GIVING CROSS.}

<more text>

etc

\end{document}
Thanks again,

-MD
-Michael D
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

centering a chapter title

Post by gmedina »

In one of my previous replies I showed you how to achieve exactly that, but you ignored my suggestion.

Edit: here's the code:

Code: Select all

\documentclass[12pt,letterpaper,twoside,openany]{book}
\usepackage[pagestyles]{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{}{20pt}{\Huge}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}

\newpagestyle{mystyle}{\sethead{}{}{}\setfoot{}{\thepage}{}}
\pagestyle{mystyle}

\begin{document}
%\maketitle
\tableofcontents

\chapter{WEEKDAY EVENING PRAYERS.}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

more text...

etc

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}
\appendix
\chapter{ON THE SIGN OF THE PRECIOUS AND LIFE-GIVING CROSS.}

more text...

etc

\end{document}
Notice that now the main chapters are built using \chapter (the unstarred version) so the \addcontentsline command is now superfluous. Also, notice the redefinition of the format for the chapters right befor the \appendix command.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

Re: centering a chapter title

Post by thedoctor818 »

Thanks. That certainly helps, & I think I am beginning to understand how & why that works.

-MD
-Michael D
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

Re: centering a chapter title

Post by thedoctor818 »

Is there a way to add unnumbered sections to the numbered appendices? I know this is getting a bit complex, but if not I will have to define a macro to accomplish what I need.

-MD
-Michael D
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

centering a chapter title

Post by localghost »

Just use the *-forms of the sectioning commands.
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

centering a chapter title

Post by thedoctor818 »

Thanks. This is what I ended up with, and it works great. A big thanks to everyone who helped on this. What I *really meant is an unnumbered section in the appendix that appears as a numbered section in the toc. Below is what I came up with. Any comments are most welcome - say, if there is an easier way to deal with that.

Code: Select all

\documentclass[12pt,letterpaper,twoside,openany]{book}
\usepackage[pagestyles]{titlesec}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{}{20pt}{\Huge}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}

\newpagestyle{mystyle}{\sethead{}{}{}\setfoot{}{\thepage}{}}
\pagestyle{mystyle}

\begin{document}
%\maketitle
\tableofcontents

\chapter{WEEKDAY EVENING PRAYERS.}

In the Name of the Father, and of the Son, and of the Holy Spirit. Amen.

more text...

etc

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries\centering}{\centering\chaptertitlename\ \thechapter}{20pt}{\Huge}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}
  
\titleformat{\section}[display]
  {\normalfont\Large\bfseries\centering}{}{20pt}{\Large}
\titlespacing*{\chapter}
  {0pt}{50pt}{40pt}  

\appendix
\chapter{ON THE SIGN OF THE PRECIOUS AND LIFE-GIVING CROSS.}

\section{text}
\subsection*{text}

more text...

etc

\end{document}
Thanks again for ALL your help.

-MD
-Michael D
thedoctor818
Posts: 92
Joined: Fri Apr 24, 2009 8:02 pm

Re: centering a chapter title

Post by thedoctor818 »

I am sorry for posting after I *thought* I had the prob solved. I used the code, exaclty as it was from the previous cods & it was working, then I began to get the following errors: both titlesec: 2 \documentclass or\documentstyle commands, & option clash for package titlesec. What do I do now???
-Michael D
Post Reply