[Tex/LaTex] redefine starred command \section*

macrossectioningtitlesec

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)

Best Answer

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}%
\usepackage{titletoc} %

\titleformat{\section}
  {\ttfamily\Large\bfseries\color{red}}
  {\thesection}
  {1em}
  {#1}%
%
\titleformat{name = \section, numberless}
  {\ttfamily\Large\bfseries\color{red}}
  {}
  {0em}
  {\addcontentsline{toc}{section}{#1}#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{Still 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} 

enter image description here