General ⇒ Centering \section
-
- Posts: 16
- Joined: Sat Dec 06, 2008 7:55 pm
Centering \section
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?
NEW: TikZ book now 40% off at Amazon.com for a short time.

Centering \section
Hi,
you could try this:
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,...
Centering \section
or have a look at the titlesec or sectsty packages
or simply switch to the memoir class where it would be as simple as
or simply switch to the memoir class where it would be as simple as
Code: Select all
\setsecheadstyle{\Large\bfseries\centering}
-
- Posts: 16
- Joined: Sat Dec 06, 2008 7:55 pm
Re: Centering \section
Thanks gmedina. That worked. Re: daleif's reply, can I switch document class in the middle of the document?
Thanks again.
Thanks again.
Re: Centering \section
no, you have to convert your entire document
-
- Posts: 16
- Joined: Sat Dec 06, 2008 7:55 pm
Centering \section
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}
Re: Centering \section
then I think you should reconsider your choice, why only center some? and not have a consistent layout
-
- Posts: 16
- Joined: Sat Dec 06, 2008 7:55 pm
Centering \section
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.daleif wrote:then I think you should reconsider your choice, why only center some? and not have a consistent layout
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.