1

For writing thesis, I am using

\documentclass[a4paper,oneside, 12pt]{book}

In it, sectioning was coming at left. I want them in center.

This has been considered before (see this).

But, I tried from its answer, the following.

\section*{\centering\textcolor{blue}{Ukaaranta }}

I was getting error.

Also, instead of this, can I delete \textcolor{blue}? Since I color them in black only.

Is it necessary to put * here?


The error was showing this:

[PDFLaTeX] Finished with exit code 1

Argument of \@sect has an extra } ...ion{\centering\textcolor{blue}{Ukaaranta }}

Paragraph ended before \@sect was complete...ion{\centering\textcolor{blue}{Ukaaranta }}

Groups
  • 157
  • What's the error message? And why is this tagged texniccenter? Of course you can delete \textcolor{blue} then –  Nov 17 '15 at 12:16
  • I am not so familiar with tags here. You may edit it with appropriate tag. – Groups Nov 17 '15 at 12:17
  • You need the * for the unnumbered section (title), otherwise use \section{\protect\centering...} –  Nov 17 '15 at 12:22
  • Have you seen my answer at all: That will prevent the error! –  Nov 17 '15 at 12:30
  • By the way: You have some questions with answers but accepted none of them, this is not how TeX.SX works ;-) –  Nov 17 '15 at 12:32
  • yes. I am doing it, and it is working with some modifications. (I added this error, because of your first comment.) – Groups Nov 17 '15 at 12:32
  • yaa. I will "accpet" answers, sorry for inconvenience. – Groups Nov 17 '15 at 12:34

3 Answers3

2

This works out of the box (remove \usepackage{showframe} later on!)

\documentclass[a4paper,oneside, 12pt]{book}

\usepackage{xcolor}
\usepackage{showframe}
\usepackage{blindtext}
\begin{document}

\section{\protect\centering\textcolor{blue}{Ukaaranta}}

\section*{\centering\textcolor{blue}{Ukaaranta}}

\blindtext[2]
\end{document}
2

You could provide the following instructions in the preamble:

\usepackage{sectsty}
\allsectionsfont{\centering}

This will center all section, subsection, and subsubsection headers. If you want to center only section-level headers, change the second command to

\sectionfont{\centering}
Mico
  • 506,678
0

As a variation on Hupfer's solution:

\documentclass[a4paper,oneside, 12pt]{book}

\usepackage{xcolor}
\usepackage{showframe}
\usepackage{blindtext}

\newcommand{\mysection}[1]{\section[#1]%
{\hfill{#1}\hfill\quad\phantom{\thesection}}}

\begin{document}

\tableofcontents

\mysection{Ukarranta}
\blindtext[2]
\end{document}

centered text, left section number

John Kormylo
  • 79,712
  • 3
  • 50
  • 120