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.

I'd like to change the format for \subsection{} without using special packages. On report.cls we find its definition

\newcommand\subsection{\@startsection{subsection}{2}{\z@}%
                                     {-3.25ex\@plus -1ex \@minus -.2ex}%
                                     {1.5ex \@plus .2ex}%
                                     {\normalfont\large\bfseries}}

But I'd like to use different fonts for the counter and for the title.

For example, for the \section{} command I'm using

{\fontsectionnumber{\color{black!50}\thesection.}\hspace{.5em}{\fontsection\MakeUppercase{#1}}} 

How to do the same for \subsection?


Edit: here is the adapted code for \section{}.

\newcommand\section{\global\@topnum\z@
                      \@afterindenttrue
                      \secdef\@section\@ssection}
\def\@section[#1]#2{\ifnum \c@secnumdepth >\z@
                       \if@mainmatter
                         \refstepcounter{section}%
                         \typeout{\thesection}%
                         \addcontentsline{toc}{section}%
                         {\protect{\color{black!30} %
                         {\fontsectionnumbertoc\numberline{\thesection.}}} {\normalfont #1} \hspace{1em} %
                         {\fontheadernumber\thepage}\hfil}%
                       \else
                         \addcontentsline{toc}{section}{#1}%
                       \fi
                    \else
                      \addcontentsline{toc}{section}{#1}%
                    \fi
                    \sectionmark{#1}%
                    \addtocontents{lof}{\protect\addvspace{10\p@}}%
                    \addtocontents{lot}{\protect\addvspace{10\p@}}%
%                    \if@twocolumn
%                      \@topnewpage[\@makechapterhead{#2}]%
%                    \else
                      \@makesectionhead{#2}%
                      \@afterheading
                    }
\def\@makesectionhead#1{%
  \vskip 5mm
  {\parindent \z@ \raggedright 
    \ifnum \c@secnumdepth >\m@ne
      %\if@mainmatter
        {\fontsectionnumber{\color{black!50}\thesection.}\hspace{.5em}{\fontsection\MakeUppercase{#1}}} 
        %\newline\nobreak
%        \vskip 0\p@
      %\fi
    \fi
    \interlinepenalty\@M
%    \large\MakeUppercase{#1} \par\nobreak
    \vskip 2mm %2.3ex \@plus.2ex
  }}
share|improve this question
    
What is the definition of \fontsectionnumber and \fontsection? –  Werner Jan 29 '13 at 18:42
    
@Werner, they are command for personal fonts: \def\fontsectionnumber{\fontsize{9}{16}\usefont{LY1}{SyntaxStd-TLF}{a}{n}} \def\fontsection{\fontsize{9}{16}\usefont{LY1}{SyntaxStd-TLF}{m}{n}} –  Sigur Jan 29 '13 at 18:44
    
@Sigur: I'm just curious: why not packages? –  nicolai.rostov Jan 29 '13 at 22:53
    
@nicolai.rostov, I'll send my file to many people to compile it on different distributions and so on. So I'd like to use many default commands as possible. –  Sigur Jan 29 '13 at 22:58
1  
\@startsection contains the definition of the headers. If you want to provide your own definition you have to use \secdef for \subsection, too. –  Marco Daniel Mar 17 '13 at 9:31
add comment

1 Answer

up vote 4 down vote accepted

The standard way to cope with this kind of problems is to use \@seccntformat, the macro that takes care of formatting the section number (any level below chapter, in the standard classes).

The usual definition is

\csname the#1\endcsname \quad

where #1 is the counter associated to the current section level. So if you define

\def\@seccntformat#1{%
  {\csname font#1number\endcsname\csname the#1\endcsname}\quad}

you can obtain any effect you prefer.

If you don't define \font<level>number, the command would be the same as \relax, so it won't raise errors.

Example.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lipsum}

\def\fontsectionnumber{\fontsize{9}{16}\usefont{T1}{DejaVuSans-TLF}{b}{n}}
\def\fontsection{\fontsize{9}{16}\usefont{T1}{DejaVuSans-TLF}{m}{n}}
\def\fontsubsectionnumber{\fontsize{7}{12}\usefont{T1}{DejaVuSans-TLF}{b}{n}}
\def\fontsubsection{\fontsize{7}{12}\usefont{T1}{DejaVuSans-TLF}{m}{n}}

\makeatletter

\def\@seccntformat#1{%
  {\csname font#1number\endcsname\csname the#1\endcsname}\quad}

\renewcommand\section{%
  \@startsection{section}{1}{\z@}%
    {-3.5ex \@plus -1ex \@minus -.2ex}%
    {2.3ex \@plus.2ex}%
    {\normalfont\fontsection}}

\renewcommand\subsection{%
  \@startsection{subsection}{2}{\z@}%
    {-3.25ex\@plus -1ex \@minus -.2ex}%
    {1.5ex \@plus .2ex}%
    {\normalfont\fontsubsection}}

\makeatother

\begin{document}

\section{This is a section title}

\lipsum[2]

\subsection{This is a subsection title}

\lipsum[3]

\end{document}

enter image description here

share|improve this answer
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.