GeneralCentering \section

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Dr. Doerke
Posts: 16
Joined: Sat Dec 06, 2008 7:55 pm

Centering \section

Post by Dr. Doerke »

With documentclass set as book, the \section{text} command left justifies my text. I want to temporarily want to center my text. How would I use renewcommand to make this work?

Recommended reading 2024:

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

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

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

Centering \section

Post by gmedina »

Hi,

you could try this:

Code: Select all

\documentclass{book}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\centering\normalfont\Large\bfseries}}
\makeatother


\begin{document}

\chapter{Dummy chapter}
\section{Test section}
text text text

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Centering \section

Post by daleif »

or have a look at the titlesec or sectsty packages

or simply switch to the memoir class where it would be as simple as

Code: Select all

\setsecheadstyle{\Large\bfseries\centering}
Dr. Doerke
Posts: 16
Joined: Sat Dec 06, 2008 7:55 pm

Re: Centering \section

Post by Dr. Doerke »

Thanks gmedina. That worked. Re: daleif's reply, can I switch document class in the middle of the document?
Thanks again.
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Centering \section

Post by daleif »

no, you have to convert your entire document
Dr. Doerke
Posts: 16
Joined: Sat Dec 06, 2008 7:55 pm

Centering \section

Post by Dr. Doerke »

Thanks again. Now that I know that it works, could you explain what is happening with this code? And what would use to switch the section back to the default left justified appearance. I only want to center certain sections. Sorry, this is the price for offering a successful solution. It is truly appreciated.
gmedina wrote:Hi,

you could try this:

Code: Select all

\documentclass{book}

\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
  {-3.5ex \@plus -1ex \@minus -.2ex}%
  {2.3ex \@plus.2ex}%
  {\centering\normalfont\Large\bfseries}}
\makeatother


\begin{document}

\chapter{Dummy chapter}
\section{Test section}
text text text

\end{document} 
daleif
Posts: 199
Joined: Wed Nov 19, 2008 12:46 am

Re: Centering \section

Post by daleif »

then I think you should reconsider your choice, why only center some? and not have a consistent layout
Dr. Doerke
Posts: 16
Joined: Sat Dec 06, 2008 7:55 pm

Centering \section

Post by Dr. Doerke »

daleif wrote:then I think you should reconsider your choice, why only center some? and not have a consistent layout
I appreciate the question and I do need to reconsider. The book is an anthology, a mixture of poetry and narrative fiction. I've considered using drop caps for the first para of the narrative fiction, but then the top left side of the page appears very heavy. A question of aesthetics.

This is my first venture with LaTeX, and I find the learning curve is a bit steep. I'm grateful for this forum, and for the responses, such as yours, that I get.
Post Reply