[Tex/LaTex] Titlesec problem, defining space before section with \titlespacing

sectioningspacingtitlesec

I am using the article document class and have trouble with the \titlespacing command of the titlesec package (explicit).

I want to have more space before the \section. MWE:

\documentclass[a4paper,12pt,fleqn,twoside]{article}
\usepackage[explicit]{titlesec}
\usepackage{varwidth}
\usepackage{xhfill}
\usepackage{parskip}

\titleformat{\section}[display]
 {\Huge}{\filleft\thesection}{-2ex}
  {\hspace*{\dimexpr-6em-10pt\relax} 
   \advance\hsize6em\advance\hsize10pt% 
   \rule[0.5ex]{6em}{1pt}\hspace{10pt}% 
    \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
   \hspace{10pt}\xrfill[0.5ex]{1pt}%
 } 

\titlespacing{\section}{0cm}{8cm}{2cm}

\begin{document}
\section{abc}
abcbacbabcbabcbacbabcbabcbabcbac
\cleardoublepage
\section{def}
abcbacbabcbabcbacbabcbabcbabcbac
\end{document}

But I have trouble with the \titlespacing command, it seems like it is getting overwritten by something.
Has it got to do with the explicit command of the titlesec package?


Another question:
With my current section heading style, is it possible to only enlarge the section number without enlarging the section text?

Best Answer

Read Enrico's comments above:

Vertical space at the beginning of pages is removed.

That should answer your first question. Coming to the second question, it is possible. I will show at least two ways.

Method -1:

Load graphicx package and use its scalebox macro like:

    \titleformat{\section}[display]
     {\Huge}{\filleft\scalebox{2}{\thesection}}{-2ex}            %% here
      {\hspace*{\dimexpr-6em-10pt\relax}
       \advance\hsize6em\advance\hsize10pt%
       \rule[0.5ex]{6em}{1pt}\hspace{10pt}%
        \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
        \hspace{10pt}\xrfill[0.5ex]{1pt}%
    }

Method - 2

Use an appropriate scalable font (like lmodern) and use \fontsize{55}{65}\selectfont\thesection

\titleformat{\section}[display]
 {\Huge}{\filleft\fontsize{55}{65}\selectfont\thesection}{-2ex}
  {\hspace*{\dimexpr-6em-10pt\relax}
   \advance\hsize6em\advance\hsize10pt%
   \rule[0.5ex]{6em}{1pt}\hspace{10pt}%
    \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
   \hspace{10pt}\xrfill[0.5ex]{1pt}%
 }

Full code:

\documentclass[a4paper,12pt,fleqn,twoside]{article}
\usepackage[explicit]{titlesec}
\usepackage{varwidth}
\usepackage{xhfill}
\usepackage{parskip}
\usepackage{lmodern}
%\usepackage{graphicx}

%\titleformat{\section}[display]
%     {\Huge}{\filleft\scalebox{2}{\thesection}}{-2ex}            %% here
%      {\hspace*{\dimexpr-6em-10pt\relax}
%       \advance\hsize6em\advance\hsize10pt%
%       \rule[0.5ex]{6em}{1pt}\hspace{10pt}%
%        \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
%        \hspace{10pt}\xrfill[0.5ex]{1pt}%
%    }

\titleformat{\section}[display]
 {\Huge}{\filleft\fontsize{55}{66}\selectfont\thesection}{-2ex}            %% here
  {\hspace*{\dimexpr-6em-10pt\relax}
   \advance\hsize6em\advance\hsize10pt%
   \rule[0.5ex]{6em}{1pt}\hspace{10pt}%
    \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
   \hspace{10pt}\xrfill[0.5ex]{1pt}%
 }

\titlespacing{\section}{0cm}{8cm}{2cm}

\begin{document}
\section{abc}
abcbacbabcbabcbacbabcbabcbabcbac
\cleardoublepage
\section{def}
abcbacbabcbabcbacbabcbabcbabcbac
\end{document}

enter image description here

You can hard code the vertical distance:

\titleformat{\section}[display]
 {\Huge}{\vspace*{20pt}\filleft\fontsize{55}{66}\selectfont\thesection}{-2ex}            %% here  added \vspace*{20pt}
  {\hspace*{\dimexpr-6em-10pt\relax}
   \advance\hsize6em\advance\hsize10pt%
   \rule[0.5ex]{6em}{1pt}\hspace{10pt}%
    \begin{varwidth}{\textwidth}\raggedright#1\end{varwidth}%
   \hspace{10pt}\xrfill[0.5ex]{1pt}%
 }
Related Question