I used this and trying to put underline as shown here

This works alone perfectly but whenever I try to add the line


instead of

\titleformat*{\section}{\bfseries\sectionfont} it says

Missing \begin{document}. ...ion}{\bfseries\sectionfont}{\thesubsection


\usepackage[explicit]{titlesec} % control over title section
\usepackage{fontspec}       % change to system font
\usepackage{anyfontsize}    % changing font size any
\usepackage{graphicx}   % import figure
\usepackage{setspace}   % line gap => \setstretch
\usepackage{parskip}    % linegap => \linespread
\usepackage{gensymb}    % degree symbol
\usepackage{ragged2e}   % Text alignment
\usepackage{xcolor} % changing color
\usepackage{sectsty}    % underline section

\newfontfamily\subsectionfont[Color=Nblack,Scale=1.34]{Garton Medium}
\newfontfamily\subsubsectionfont[Color=Nblack,Scale=1.34]{Garton Medium}



or if I remove [explicit] and add * after \titleformat it gives

Illegal parameter number in definition of \ttlf@section. ...esubsection}{1em}{#1}[{\titlerule[0.8pt]}]

Also, like to have First Word Big caps and others small caps

  • Welcome to TeX.SX! Your example is incomplete -- \documentclass is missing, and other issues ....
    – user31729
    Commented Aug 24, 2016 at 14:11
  • Why did you edit my changes to improve your format away? :-(
    – user31729
    Commented Aug 24, 2016 at 14:14
  • oops, maybe I'm editing at the same time, sorry. and how to write code structure in block?
    – Dr.PB
    Commented Aug 24, 2016 at 14:16
  • Hi @Runar, it's a very nice edit. How you are doing the "Missing..." part and code part? It's really looking great.
    – Dr.PB
    Commented Aug 25, 2016 at 4:19
  • That would be a blockquote, one of the buttons above the textfield when posting.
    – Runar
    Commented Aug 25, 2016 at 4:25

1 Answer 1


The syntax of \titleformat and \titleformat* is very different; the latter just takes two arguments, the former is more complex.

One rarely needs explicit: the last mandatory argument to \titleformat can end with a one-parameter macro, as in the example below.

Beware also that titlesec and sectsty are incompatible with each other. Since you need the former for its advanced features, don't load sectsty.


\usepackage{fontspec}       % change to system font
\usepackage{titlesec} % control over title section

  \seq_set_split:Nnn \l_tmpa_seq {~} {#1}
  \seq_pop_left:NN \l_tmpa_seq \l_tmpa_tl
  \seq_put_left:Nn \l_tmpa_seq {\MakeUppercase{\l_tmpa_tl}}
  \seq_use:Nn \l_tmpa_seq {~}

\newfontfamily\sectionfont{TeX Gyre Heros}
\newfontfamily\subsectionfont{TeX Gyre Heros}


\section{Introduction and something else}

I used fonts I have on my system (and I recommend you not to use Garton).

The \firstword macro splits the argument at spaces, isolates the first item, encloses it into \MakeUppercase and finally reinstates it for printing all items separated by spaces.

enter image description here

  • 1. It's running alone, but with not with my doc. 2. I tried to find what's wrong and got \usepackage{sectsty} as the culprit. 3. Thank you for your efforts. 4. I'm very new to TEX, can you pl suggest any good macro tutorial. (I didn't understand single bit of ExplSyntax) 5. Please elaborate the working of these:{1em}{} Again thank you very much.
    – Dr.PB
    Commented Aug 25, 2016 at 4:16
  • @Mr.EU, the stuff between ExplSyntaxOn and ExplSyntaxOff is part is using the new and experimental(but stable) syntax from LaTeX3. The same code could ofcourse be written using more accoustomed latex-macros, possibly using xstring. Ill have a look at it later today, when I get to a computer. Regarding {1em}{}, the manual for titlesec explains it really well.
    – Runar
    Commented Aug 25, 2016 at 4:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .