# How to put section number into the right side of section title in LaTeX?

I am a novice for LaTeX, so need you guy's help.

I am wondering how to change section style in order to put the section number into the right side of section title in LaTeX, especially memoir class. So, I want it to show like [chapter number] section title [section number]

For example, let a chapter has three sections like section one, section two, and section three. Then, they should appear like

1. section one 1.
1. section two 2.
1. section three 3.


Can anybody do that for me?

-

## migrated from stackoverflow.comAug 5 '11 at 11:24

This question came from our site for professional and enthusiast programmers.

That is not possible without major reprogramming –  daleif Aug 5 '11 at 12:06
Welcome to TeX.sx! Your question was migrated here from another stackexchange site. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  N.N. Aug 9 '11 at 8:48

In case you do not want the section number to the right of the section title in the table of contents (see BernS' answer), you could use the titlesec package to redefine the section header layout:

\documentclass{memoir}

\usepackage{lipsum}

\usepackage[explicit]{titlesec}
% \titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before>}[<after>]
\titleformat{\section}[hang]{\normalfont\Large\bfseries}%
{\thechapter.}{4pt}%
{#1 \arabic{section}.}

\begin{document}
\tableofcontents
\chapter{Chapter}
\section{Section one}
\lipsum[1]
\section{Section two}
\lipsum[2]
\section{Section three}
\lipsum[3]
\end{document}


Credits go to Raphink's answer to my question regarding a problem I had with reading documentation properly. Consider voting his answer up. ;-)

-
While I don't know what the OP intended exactly, this seems to be the easiest solution (and most useful one to me personally, because it cleared a misunderstanding I had about titlesec's formatting). Hence the (token) bounty. –  Caramdir Aug 13 '11 at 19:17
@Caramdir: /me takes a humble bow. Being able to give something back to your community here (which has helped me much on my first venture into LaTeX) is a good feeling. –  DevSolar Aug 14 '11 at 8:15

It is possible to manually redefine the \section (and \section*, assuming that this even makes sense) command to allow for this. For the moment

• \section{<sec title>} produces <chapnum> \quad <sec title> \quad <secnum>; and
• \section*{<sec title>} produces <chapnum> \quad <sec title>.

The former produces the usual entry in the table of contents since the manual redefinition of \section{...} does not include a redefinition of \thesection. Also, references made to sections will be referenced as <chapnum>.<secnum> (or, more specifically, \thechapter.\arabic{section}) by default. However, this behaviour as well as that of the sectioning command, can be changed if needed.

The basic redefinition was taken from Vincent Zoonekynd's LaTeX page on sections. Here's a minimal example:

\documentclass{memoir}
\usepackage[margin=15mm]{geometry}% Page layout
\usepackage{lipsum}% Dummy text

% Taken from http://zoonek.free.fr/LaTeX/LaTeX_samples_section/0.html
\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}%
\noindent
\begingroup
\leavevmode\Large\bfseries\raggedright
#2
\par
\endgroup
\vskip 2ex\nobreak
\protect\numberline{\thesection}% ToC entry
#1}%
}
\def\unnumberedsectionwithtwoarguments[#1]#2{%
\ifhmode\par\fi
\removelastskip
\vskip 3ex\goodbreak
%  \refstepcounter{section}%
\noindent
\begingroup
\leavevmode\Large\bfseries\raggedright
\leavevmode\Large\bfseries\raggedright
#2
\par
\endgroup
\vskip 2ex\nobreak
%    \protect\numberline{\thesection}% ToC entry
#1}%
}
\makeatother

\begin{document}
\chapter{First chapter} \lipsum[1]
\section{First section} \lipsum[2]
\section{Second section} \lipsum[3]
\section{Third section} \lipsum[4]
\section{Final section} \lipsum[5]
\end{document}


...and the associated output:

I used the geometry package merely for layout purposes (so the MWE fits on one page) and the lipsum package for dummy text.

-

The following should look like what you'd want to have (as described in the text, so "[chapter]. Title [section]."):

\documentclass{memoir}
\usepackage{lipsum}
\usepackage[utf8x]{inputenc}

\newcommand\secstore{}
\newcommand\mythesection{\arabic{chapter}.}

\newcommand\mysection[1]{%
\let\secstore\thesection%
\let\thesection\mythesection%
\section{#1 \arabic{section}.}%
\let\thesection\secstore%
}%

\begin{document}
\chapter{Test}

\mysection{This is section 1}
\lipsum[1]

\mysection{This is section 2}
\lipsum[2]

\mysection{This is section 3}
\lipsum[3]
\end{document}


If you want it the same way as in your sample "[section]. Title [section]." then the following command should be changed above:

\newcommand\mythesection{\arabic{section}.}


Anyway, it's also possible to save and overload \section so that it is not necessary to use \mysection.

And here is the output provided by the solution above:

-
I have two comments. First, there should be no need to \renewcommand at each of the macro invocations. Second, * is not a part of control sequence names; thus your second \let lets \thesection to the character * and then \secstore is expanded. –  Andrey Vihrov Aug 9 '11 at 9:18
@Andrey Vihrov I changed the code above according your comments. –  BernS Aug 9 '11 at 9:27
This puts the section number to the right of the section title in the table of contents, too. –  DevSolar Aug 9 '11 at 11:27
@DevSolar, I hope this was intended by the question creator too... –  BernS Aug 9 '11 at 11:45