2

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 }}

  • What's the error message? And why is this tagged texniccenter? Of course you can delete \textcolor{blue} then – user31729 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...} – user31729 Nov 17 '15 at 12:22
  • Have you seen my answer at all: That will prevent the error! – user31729 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 ;-) – user31729 Nov 17 '15 at 12:32
3

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}
|improve this answer|||||
  • Mico: Great. This works well, with less commands. Thank you very much for the help. – Groups Nov 18 '15 at 3:47
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}
|improve this answer|||||
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

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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