Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\section{Introduction}

gives something like

1. Introduction

How can I rather obtain the following header?

Section 1. Introduction

share|improve this question
    
For example: \def\thesection{Section~\arabic{section}.} –  Eddy_Em Feb 4 '13 at 7:19
    
Should this only affect the section title as it's set, and not the reference? What \documentclass are you using? –  Werner Feb 4 '13 at 7:25
    
@Werner: I use the \documentclass{article}. There is no table of content, so it should only affect the section title. Thanks! I will try Eddy_Em' solution. –  user7064 Feb 4 '13 at 7:40
add comment

2 Answers

up vote 8 down vote accepted

Without using hyperref and within the default document classes, you could patch \@sect to conditionally insert Section~ based on whether you are in \section or not:

enter image description here

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\def\@seccntformat#1{\csname the#1\endcsname.\quad}
\patchcmd{\@sect}% <cmd>
  {\relax\@svsec}% <search>
  {\relax\ifnum#2=1\relax Section~\fi\@svsec}% <replace>
  {}{}% <success><failure>
\makeatother
\begin{document}
\section{A section}\label{section}
\subsection{A subsection}
See Section~\ref{section}.
\end{document}

The patch is provided by etoolbox's \patchcmd. It searches fo \relax\@svsec and inserts the condition inbetween. The condition checks if the level of the sectional unit matches "level 1" (that of \section), as is the case when looking at the definition in article.cls (the second argument to \@startsection):

\newcommand\section{\@startsection {section}{1}{\z@}%
                                   {-3.5ex \@plus -1ex \@minus -.2ex}%
                                   {2.3ex \@plus.2ex}%
                                   {\normalfont\Large\bfseries}}

For detail on the components of \@startsection, see Where can I find help files or documentation for commands like \@startsection for LaTeX?

share|improve this answer
add comment

You can use a very useful feature of TeX; a command called as

\csname foo\endcsname

will be silently ignored (actually \relax would be executed, which does nothing) if \foo isn't defined.

So doing

\documentclass{article}
\makeatletter
\def\@seccntformat#1{\csname named#1\endcsname\csname the#1\endcsname.\quad}
\makeatother
\newcommand{\namedsection}{Section }

\begin{document}
\section{A section}\label{section}
\subsection{A subsection}
See Section~\ref{section}.
\end{document}

you reach your aim.

enter image description here

If you also want to add "Subsection" in front of the subsection number, just add

\newcommand{\namedsubsection}{Subsection }

The macro \@seccntformat is described, with similar tricks, in the TeX FAQ, see Adjusting the presentation of section numbers

share|improve this answer
    
Thank you :-) @egreg –  user7064 Feb 5 '13 at 7:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.