3

With the code below, I have a very large space between the section 1 heading and subsection 1.1 heading. I've tried to change the \titlespacing options but I still can't reduce this large space.

What adjustments can I make to my code?

\documentclass[twoside,a4paper]{article}

\usepackage{blindtext}

\usepackage{graphicx}

\usepackage[dvipsnames]{xcolor}
\definecolor{verydarkblue}{HTML}{000052}

\XeTeXinputencoding iso-8859-1

\usepackage{geometry}
\geometry{a4paper,total={210mm,297mm},
 left=20mm,right=20mm,top=25mm,bottom=25mm,}

\usepackage{setspace}
\onehalfspacing

\usepackage[compact]{titlesec}
\titlespacing\section{0pt}{0pt}{0pt}
\titlespacing\subsection{0pt}{0pt}{0pt}
\titlespacing\subsubsection{0pt}{0pt}{0pt}

\usepackage{parskip}

\usepackage{fontspec}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont{Calibri}

\date{}

\begin{document}

\newpage

\textcolor{verydarkblue}{\section*{\textbf{\textsc{{section 0}}}}}
\blindtext

\textcolor{verydarkblue}{\section{\textbf{\textsc{{section 1}}}}}
\textcolor{verydarkblue}{\subsection{\textit{subsection 1.1}}}
\blindtext

\end{document}
  • Welcome to TeX SE! Don't put explicit markup in the argument to \section etc. Put the formatting in your configuration i.e. when you set them up using titlesec's commands. That way, it is easy to keep things both consistent and flexible. You probably need to include some stretch in the spacing you are setting up. See page 5 of titlesec's manual for a way to do this using * settings provided by the package. – cfr Oct 25 '14 at 16:50
  • 1
    \textcolor{verydarkblue}{\section*{\textbf{\textsc{{section 0}}}}}You should never have formatting in the argument or around sectioning commands, or number sections "by hand". In particular if you surround the heading by a group like this you will mess up the code latex uses for controlling the following paragraph. Just use \section{title for section zero} and specify fonts and colours elsewhere. – David Carlisle Oct 25 '14 at 16:56
2

You should use the features of titlesec for setting color and font of titles.

\documentclass[twoside,a4paper]{article}

\usepackage{fontspec}
\usepackage[dvipsnames]{xcolor}
\usepackage[compact]{titlesec}
\usepackage{graphicx}

\usepackage{blindtext}

\setmainfont{TeX Gyre Heros}% I don't own Calibri

\definecolor{verydarkblue}{HTML}{000052}

\titleformat{\section}
  {\color{verydarkblue}\Large\bfseries}
  {\thesection}
  {1em}
  {\scshape}
\titleformat{\subsection}
  {\color{verydarkblue}\normalfont\large\bfseries}
  {\thesubsection}
  {1em}
  {\scshape}
\titleformat{\subsubsection}
  {\color{verydarkblue}\normalfont\normalsize\bfseries}
  {\thesubsubsection}
  {1em}
  {\itshape}

\begin{document}

\section*{section 0}
\blindtext

\section{section 1}
\subsection{subsection 1.1}
\blindtext

\end{document}

enter image description here

Don't load xunicode and xltxtra; avoid using \XeTeXinputencoding for new documents: save them as UTF-8.

  • Excellent, thanks - it is possible to make the heading numbers the same colour as the heading text? I have to use xunicode, xltxtra and \XeTexinputencoding to support foreign characters. – user2568648 Oct 25 '14 at 17:05
  • 1
    @user2568648 Move the \color command to the second argument of \titleformat. I'll fix the code. You don't need xunicode, xltxtra or \XeTeXinputencoding for supporting foreign characters. Just be sure to save your file as UTF-8. – egreg Oct 25 '14 at 17:08

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.