Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to put each section's content inside a center environment, that means when I write the code

\section{First}
texts\dots
text text text
\section{Second}
texts\dots
text text text

it will be displayed as

I.1 First
    texts...
text text text

I.2 Second
    texts...
text text text

How to get this?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

I would think the easiest way to do this would be to redefine the \section command. It's original definition from book.cls (by seeing your section numbering) is

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

By adding \raggedright to the font selection, the section formatting will be localized, and we can set the entire document using \centering for a centred alignment.

Left-aligned section; centred text

\documentclass{book}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\makeatletter
\renewcommand{\thechapter}{\Roman{chapter}}% Redefine chapter numbers
\renewcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\raggedright\normalfont\Large\bfseries}}
\makeatother
\begin{document}
\centering
\chapter{A chapter}
\section{First section} \lipsum[1]
\section{Second section} \lipsum[2]
\section{Last section} \lipsum[3]
\end{document}

lipsum was used to produce dummy text, lorem ipsum style.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.