How to center an unnumbered section name?

I have a chapter chap1.tex in latex project project.tex which has the following sections:

\chapter{Overview}
\section*{Introduction}
\section{Model}
\section{Discussion}


When I run my latex project project.tex, I will get something like this:

I would like to make Introduction in the center. How to do this?

I tried \centering\section*{Introduction}

-
Do you only want unnumbered sections centred? –  Alan Munn Jul 28 '14 at 17:01
Yes. For example the introduction section. –  Chiba Jul 28 '14 at 17:02
A comment up front: It may look very weird if unnumbered section headers are centered but numbered sections are not. To center-set both numbered and unnumbered section headers, you could load the sectsty package and issue the directive \sectionfont{\centering}. –  Mico Jul 28 '14 at 17:05

2 Answers

Since you are using a \section* for it, there are no complications for the table of contents.

\documentclass{book}

\begin{document}
\tableofcontents

\chapter{Overview}
\section*{\hfil Introduction\hfil}
\section{Model}
\section{Discussion}
\noindent\hrulefill
\end{document}


To address both a possible criticism of non-generality as well as the suggestion of egreg, one could implement the above idea as shown below:

\documentclass{book}
%\def\myformat#1{\hfil #1\hfil}% OR ALTERNATELY
\def\myformat#1{\centering#1}
\begin{document}
\tableofcontents

\chapter{Overview}
\section*{\myformat{Introduction}}
\section{Model}
\section{Discussion}
\noindent\hrulefill
\end{document}


In this way, a desire at some future point to change the format for all such starred sections would require only a single-line change to the document, that is, the definition of \myformat.

-
Nice. Thank you. –  Chiba Jul 28 '14 at 17:17
Probably \section*{\centering Introduction} is better. –  egreg Jul 28 '14 at 19:22
my apologies again - please see my updated answer :) –  cmhughes Jul 28 '14 at 20:34

One of the most useful aspects of using LaTeX and friends is that you can separate content from form; if you specify \hfil...\hfil for every unnumbered section, what happens if you change your mind later on?

As an alternative, you can use (for example) the titlesec package; the \titleformat command has syntax:

% from the titlesec package
%\titleformat{ command }
%             [ shape ]
%             { format }{ label }{ sep }{ before-code }[ after-code ]


Here's the complete code to play with:

% arara: pdflatex
\documentclass{book}
\usepackage{titlesec}
% from the titlesec package
%\titleformat{ command }
%             [ shape ]
%             { format }{ label }{ sep }{ before-code }[ after-code ]
% \section*
\titleformat{name=\section,numberless}
{\filcenter\Large\bfseries}
{}
{.5em}
{}

\begin{document}
\tableofcontents

\chapter{Overview}
\section*{Introduction}
\section{Model}
\section{Discussion}
\noindent\hrulefill
\end{document}

-
Obviously, one could \def\myformat#1{\hfil #1\hfil} and invoke \section*{\myformat{Introduction}}. So I think your discouragement against use should be taken in the context of a likely implementation. A later change of mind would require only a single line edit. –  Steven B. Segletes Jul 28 '14 at 19:35
@StevenB.Segletes you're absolutely right - I certainly didn't mean it to sound as harsh as it did, and will re-write that sentence; my apologies :) –  cmhughes Jul 28 '14 at 20:25
Likewise, I'm sorry for my hyperventilation. –  Steven B. Segletes Jul 28 '14 at 20:44