# Adding text to the section numbering

I wish to add some text prior to the number given to a subsection, e.g.:

Task 1.1  Blablabla
...


How?

-
Can you please be a little bit more specific? Do you need this Task text for a special environment, like a theorem or for what? BTW: Welcome to TeX.sx! –  Kurt Nov 10 '12 at 22:23
Thanks. No special environment. Task is just an example text. I would like to have a word like that before the number for a subsection, and that's all. –  Steeven Nov 10 '12 at 22:33

To add text before the section, you can use:

\renewcommand{\thesection}{Text \arabic{section}}


or for subsection you can use:

\renewcommand{\thesubsection}{Text \arabic{section}}


## Code: section

\documentclass{article}

\renewcommand{\thesection}{Text \arabic{section}}

\begin{document}
\section{First section}
Some text.

\section{Second section}
Some more text.
\end{document}


## Code: subsection:

\documentclass{article}

\renewcommand{\thesubsection}{Text \arabic{subsection}}

\begin{document}
\section{First section}
\subsection{First sub section}
Some text.
\subsection{Second sub section}
Some more text.
\end{document}

-
This is great and works. But some other problem appears when I use the \renewcommand{\thesubsection}{Text \arabic{section}}. The numbering of the subsection suddenly doesn't work. @Peter, if you make two subsections in your example, they both have the number 1. Can that be fixed? –  Steeven Nov 10 '12 at 22:42
Clearly LaTeX is not smart enough to know that when I said \arabic{section}, that I obviously meant \arabic{subsection}. :-) Anyway, sorry about that mistake - have updated answer. –  Peter Grill Nov 10 '12 at 22:47
Precisely ;) Thanks alot. (By the way, you must update it in two places in your answer...) –  Steeven Nov 10 '12 at 23:50
@Steeven: Two places? Only the \renewcommand needed updating. I added two subsections to show that it functioned as desired. –  Peter Grill Nov 10 '12 at 23:56
Oh well, I just meant the single line \renewcommand{\thesubsection}{Text \arabic{section}} above your example. –  Steeven Nov 11 '12 at 13:37

Peter's answer has the disadvantage of printing the text you put before subsection numbers in references to the subsections and in the ToC, as well.

To avoid that, instead of renewing the meaning of \thesubsection, it's better to load the titlesec package and define

\titleformat{\subsection}{\normalfont\large\bfseries}{Task \thesubsection}{1em}{}


MWE:

\documentclass{article}

\usepackage{titlesec}

\begin{document}
\tableofcontents
\section{A section}
\subsection{First subsection}\label{subsec:first}
Some text from subsection \ref{subsec:second}.
\subsection{Second subsection}\label{subsec:second}
Some text from subsection \ref{subsec:first}.
\end{document}


Output:

If you want similar behavior for sections, you can use something like

\titleformat{\section}{\normalfont\Large\bfseries}{Text \thesection}{1em}{}


If you also want that word before subsection numbers in the ToC, add the following code to your preamble

\usepackage[titles]{tocloft}
\newlength\mylength
\settowidth\mylength{\cftsubsecpresnum}


to get

-