I wish to add some text prior to the number given to a subsection, e.g.:
Task 1.1 Blablabla
...
Task 1.2 Blablabla
How?
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}}
section
\documentclass{article}
\renewcommand{\thesection}{Text \arabic{section}}
\begin{document}
\section{First section}
Some text.
\section{Second section}
Some more text.
\end{document}
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}
\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?
\arabic{section}
, that I obviously meant \arabic{subsection}
. :-) Anyway, sorry about that mistake - have updated answer.
Commented
Nov 10, 2012 at 22:47
\renewcommand
needed updating. I added two subsection
s to show that it functioned as desired.
Commented
Nov 10, 2012 at 23:56
\renewcommand{\thesubsection}{Text \arabic{section}}
above your example.
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}
\titleformat{\subsection}{\normalfont\large\bfseries}{Task \thesubsection}{1em}{}
\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}
\renewcommand{\cftsubsecpresnum}{Task\space}
\newlength\mylength
\settowidth\mylength{\cftsubsecpresnum}
\addtolength\cftsubsecnumwidth{\mylength}
to get
Task
text for a special environment, like a theorem or for what? BTW: Welcome to TeX.sx!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.