# redefine starred command \section*

with \usepackage[explicit]{titlesec} I have defined \section like

\titleformat{\section}
{\ttfamily\Large\bfseries\color{red}}
{\thesection}
{1em}
{#1}


i want to redefine the starred version of section \section* To become like \section (with number) Except that the text after Comes in front of section heading (run in)

-
You don't need the explicit option: remove it and just leave the last argument empty. –  egreg Jul 21 '14 at 8:15

There's a numberless key (to be used with name) that does the job:

 \documentclass[12pt, a4paper]{article}%

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[x11names]{xcolor}
\usepackage[explicit]{titlesec}%

\titleformat{\section}
{\ttfamily\Large\bfseries\color{red}}
{\thesection}
{1em}
{#1}

\titleformat{name = \section, numberless}[runin]
{\ttfamily\Large\bfseries\color{red}}
{\stepcounter{section}\thesection}
{1em}
{#1}

\begin{document}

\section{A Numbered Section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\section*{An Unnumbered Section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\section{Another Numbered Section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\end{document}


However, be aware that it will be more complex if you also want a table of contents as it would then be numbered and in run-in style.

-
\section* with section number and run in mode –  salim bou Jul 21 '14 at 8:38
I misunderstood. OK, I'll modify at once. –  Bernard Jul 21 '14 at 8:41
@seloumi: I updated my answer, but there will be problems if you want a table of contents. –  Bernard Jul 21 '14 at 8:59
by unnumbered you mean numberless, right? :) –  clemens Jul 21 '14 at 11:04
Yes. I wanted to make a difference between the meaning and the key that's used. –  Bernard Jul 21 '14 at 11:21

If you do not need a table of contents you can delete the lines for the toc redefinition. However a solution with a special macro like \Ssection} maybe a better choice, then \ţableofcontents hasn't to be redefined:

\documentclass[12pt, a4paper]{article}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}%
\let\TableOfContents\tableofcontents
\renewcommand\tableofcontents{{\titleformat{\section}%
{\Large\bfseries}{\thesection}{1em}{##1}\let\section\Section\TableOfContents}}
\let\Section\section
\makeatletter
\renewcommand\section{\@ifstar\starsection\Section}
\makeatother
\newcommand\starsection[1]{%
\par\bigskip\noindent\refstepcounter{section}%
{\ttfamily\Large\bfseries\textcolor{red}{\thesection\hspace{1em}#1}\hspace{1em}}}

\titleformat{\section}
{\ttfamily\Large\bfseries\color{red}}
{\thesection}
{1em}
{#1}

\begin{document}
\tableofcontents
\section{A Numbered Section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\section*{An Unnumbered Section}
Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text.

\end{document}


-
Is there a solution if one wants \contentsname be typeset ‘ normally’? –  Bernard Jul 21 '14 at 12:02
sure. Redefine \titleformat –  Herbert Jul 21 '14 at 12:17