4

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?

  • 1
    Vertical space at the beginning of pages is removed. – egreg Dec 6 '13 at 23:20
3

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}%
 }
  • 1
    I think you are trying to mimic chapters. In that case you better use book/report class and play with chapter styles. – user11232 Dec 6 '13 at 23:43
  • Thx for the help with the section style! I did not understand the comment about my first question: "Vertical space at the beginning of pages is removed." Why is it removed and how do i undo it? – Mike Dec 7 '13 at 14:47
  • @Mike It is the default behaviour. Can you be more specific? If you want to mimic chapters, it is better to follow my previous comment. – user11232 Dec 8 '13 at 1:34
  • @Mike See the last edit. – user11232 Dec 8 '13 at 1:38
  • Thought i had to use the \titlespacing command but this solves my problem! Thx for the help! – Mike Dec 8 '13 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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