I am trying to customize my \section
and \subsection
command in such a way that they have two different styles. With the following code I am able to draw squared shades around the section numbering.
\documentclass[a4paper,9pt]{extarticle}
\usepackage[utf8]{inputenc}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{titlesec}
\titleformat*{\section}{\LARGE\mdseries}
\titleformat*{\subsection}{\Large\bfseries}
\usepackage{color}
\makeatletter
\definecolor{sectcolor}{rgb}{0.9,0.9,0.9}
\let\origsection\section
\let\origsubsection\subsection
\def\thesectiontext{\@arabic\c@section.}
\def\thesubsectiontext{\thesectiontext\@arabic\c@subsection}
\global\newsavebox{\sectbox}
\def\makesectbox#1{\savebox\sectbox{\colorbox{sectcolor}
{\makebox[1.47cm][r]{\normalfont\large\bfseries#1}}}}
\renewcommand \thesection {\usebox{\sectbox}}
\renewcommand \thesubsection {\usebox{\sectbox}}
\renewcommand\section{\@ifstar{\myheading}{\mysection}}
\newcommand\mysection[1]{\sectprelude{section}%
{\thesectiontext}\origsection{#1}\mdseries}
\titleformat{\mysection}
{\fontsize{16}{19}\selectfont}{\thesection}{1em}{}
\newcommand\myheading[1]{\sectprelude{section}%
{\thesectiontext}\origsection*{#1}}
\renewcommand\subsection[1]{\sectprelude{subsection}%
{\thesubsectiontext}\origsubsection{#1}}
\newcommand\sectprelude[2]{%
\addtocounter{#1}{1}\makesectbox{#2}\addtocounter{#1}{-1}}
\makeatother
\makeatletter
\def\@seccntformat#1{\llap{\csname the#1\endcsname\quad}}
\makeatother
\begin{document}
\section{Neuromancer}
\vspace{1em}
Count Zero Interrupt ...
\section{Foundation series}
\subsection{Foundation}
\subsection{Foundation and Empire}
\end{document}
The result of this code can be seen here:
I however want, that there are no shaded boxes around the \subsection
numbering and that the section number of the \section
command is aligned with the section number of the \subsection
command (meaning all the 2's on the left side of the dot have the same horizontal coordinate)
Does someone know a solution?
sectsty &
titlesec` packages or the special commands inmemoir
class?\@sect
doing the basic stuff, it's possible to decide there if it's a section or asubsection