# How to show section title before section number

The default style is section number and then section title, however I want it the other way around. Haven't been able to find a solution that doesn't give me strange errors, so any help would be appreciated.

-

You can use the titlesec package:

\documentclass{article}
\usepackage[explicit]{titlesec}

\titleformat{\section}{\normalfont\Large\bfseries}{}{0em}{#1\ \thesection}

\begin{document}

\section{A Test Section}
\section{Another Test Section}

\end{document}


Similar redefinitions can be done for the other sectional units, if required.

-
Exactly what i was looking for! Thank you all so much :) –  olav Jun 3 '12 at 22:56

In ConTeXt you can use

\setuphead[alternative=command, command=\swap]
\def\swap#1#2{#2\space#1}

\starttext
\startTEXpage[offset=5mm]
\chapter{A chapter}
\section{A section}
\subsection{A subsection}
\stopTEXpage
\stoptext


which gives

-
After seeing some of the answers that you have given using ConTeXt which I've also answered but using LaTeX, I am increasingly tempted to start studying ConTeXt seriously. –  Gonzalo Medina Jun 2 '12 at 17:08
@GonzaloMedina: Definitely give it a shot. –  Aditya Jun 2 '12 at 17:11

Here is an example (MWE) for the standard report-class. The code is copied from Vincent Zoonekynd and modified. The code for the book-class will be little different:

\documentclass{report}

\makeatletter
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries #1 \quad
\ifnum \c@secnumdepth >\m@ne
\Huge\bfseries
\thechapter
\par\nobreak
\fi
\vskip 40\p@
}}
\vspace*{50\p@}%
{\parindent \z@ \raggedright
\normalfont
\interlinepenalty\@M
\Huge \bfseries  #1\par\nobreak
\vskip 40\p@
}}
\makeatother

\begin{document}
\chapter*{Test}
\chapter{Introduction}
\end{document}


And if you use article-class and only needs \section, here more code from the same source, slightly modified to suit your needs:

\documentclass{article}
\usepackage{lipsum}

\makeatletter
\def\section{\@ifstar\unnumberedsection\numberedsection}
\def\numberedsection{\@ifnextchar[%]
\numberedsectionwithtwoarguments\numberedsectionwithoneargument}
\def\unnumberedsection{\@ifnextchar[%]
\unnumberedsectionwithtwoarguments\unnumberedsectionwithoneargument}
\def\numberedsectionwithoneargument#1{\numberedsectionwithtwoarguments[#1]{#1}}
\def\unnumberedsectionwithoneargument#1{\unnumberedsectionwithtwoarguments[#1]{#1}}
\def\numberedsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
\refstepcounter{section}%
\hbox to \hsize{%
}
\vskip 2ex\nobreak\noindent%
\protect\numberline{\thesection}%
#1}%
\ignorespaces}
\def\unnumberedsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
\hbox to \hsize{%
\vtop{\parindent=0pt\leavevmode\Large\bfseries\raggedright #2\par}%
}
\vskip 2ex\nobreak\noindent%
#1}%
\ignorespaces}
\makeatother

\pagestyle{empty}
\begin{document}
\lipsum[1-2]
\section*{Introduction}
\lipsum[3-4]
\section{Introduction}
\lipsum[5-6]
\end{document}


In any case, it demonstrates clearly how much simpler life is due to titlesec and secstyle.

-
The question was about sections. –  egreg Jun 3 '12 at 16:02
A chapter is also a section of a text, and \chapter{} a sectioning command, isn't it? The question did not informed about the class. –  Sveinung Jun 3 '12 at 22:09
Code for \section is added. Much more work than I anticipated. Use of secsty or titlesecis recommended. (Or use KOMA-script or memoir.) –  Sveinung Jun 4 '12 at 13:07