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.

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.

share|improve this question
add comment

3 Answers

up vote 14 down vote accepted

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}

enter image description here

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

share|improve this answer
    
Exactly what i was looking for! Thank you all so much :) –  olav Jun 3 '12 at 22:56
add comment

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

enter image description here

share|improve this answer
5  
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
add comment

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
\def\@makechapterhead#1{%
  \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@
  }}
\def\@makeschapterhead#1{%
  \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{%
    \vtop{\parindent=0pt \leavevmode\Large\bfseries\raggedright #2\quad\thesection\par}%
    }
  \vskip 2ex\nobreak\noindent%
  \addcontentsline{toc}{section}{%
    \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%
  \addcontentsline{toc}{section}{%
    #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.

share|improve this answer
    
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
1  
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
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.