9

I have my document like this (in main.tex):

% Document type: report (master/bachelor thesis)
\documentclass[a4paper,12pt,appendix]{report}

\input{template/FormatsAndDefs.tex} % here I have specified various format settings

\begin{document}
  \input{thesis.tex}
\end{document}

In FormatsAndDefs.tex I have specified format for chapter titles like this:

\usepackage[T1]{fontenc}
\usepackage{titlesec}
% various other packages

\titleformat{\chapter}
  {\normalfont\Large\bfseries}{\thechapter}{.5em}{\vspace{.5ex}}[\titlerule]
\titlespacing*{\chapter}      
    {0pt}{0pt}{15pt}

So my title chapters are formatted like this: enter image description here

How can I make this chapter title "Introducion" in ALL UPPERCASE while keeping it bold and underlined?

I have tried to use \MakeUppercase :

\titleformat{\chapter}
  {\normalfont\LARGE\bfseries}{\MakeUppercase{\thechapter}}{.5em}{\vspace{.5ex}}[\titlerule]

but chapter remained still the same as shown in the picture.

Johannes_B
  • 24,235
  • 10
  • 93
  • 248
PeterB
  • 276

2 Answers2

12

Use the correct places for the various parts: the spacing before the rule should go in the last argument (the optional one), so you can finish the title argument with a one parameter macro such as \MakeUppercase.

\documentclass{report}

\usepackage{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}
  {\normalfont\Large\bfseries}
  {\thechapter}
  {.5em}
  {\MakeUppercase}
  [\vspace{.5ex}\titlerule]

\titlespacing*{\chapter}
  {0pt}
  {0pt}
  {15pt}

\begin{document}

\chapter{Introduction}

\lipsum

\end{document}

enter image description here

egreg
  • 1,121,712
9

You need to have a handle on the chapter title, and the only way to do this is to use the explicit option with titlesec:

enter image description here

\documentclass{report}

\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\titleformat{\chapter}
  {\normalfont\Large\bfseries}{\thechapter \quad \MakeUppercase{#1}}{.5em}{\vspace{.5ex}}[\titlerule]
\titlespacing*{\chapter}
  {0pt}{0pt}{15pt}

\begin{document}

\chapter{Introduction}

\lipsum

\end{document}

This option allows you to explicitly state the sectional title as #1, where you can now wrap it within \MakeUppercase.

Werner
  • 603,163
  • Ok, now my \chapter titles are uppercase and as I wanted them BUT my \section titles are underlined AS WELL... and I dont want them underlined. There is code right under the chapter title format :

    \titleformat{\section} {\normalfont\large\bfseries}{\thesection}{1em}{} As you can see there is no [\titlerule] specified. What is this strange behaviour?

    – PeterB Nov 17 '16 at 01:14
  • @PeterB.: I don't get that in my output when I use \titleformat{\section}{\normalfont\large\bfseries}{\thesection \quad #1}{1em}{}... – Werner Nov 17 '16 at 01:17
  • It was my mistake, because I deleted and replaced \usepackage[sf,sl,outermarks]{titlesec} but I just needed to add explicit to square brackets. Now it works like a charm, thank you sir. – PeterB Nov 17 '16 at 01:33
  • 1
    Would you please try \chapter*{whatever}? – egreg Nov 17 '16 at 08:03
  • @egreg: You'll have to read the titlesec documentation to see the author discourages this. – Werner Nov 17 '16 at 08:17
  • Whatever Javier thinks about it, your code is wrong, sorry. – egreg Nov 17 '16 at 08:29