19

Sorry. I am new at this and it is my first time asking a question. I was reading this posting:

how to change chapter/section style in tufte-book?

How does one also get the subsections to change to the same colors as the sections as in the top image?

Also, how does one make the chapter have a similar style to the section headings?

3
  • 1
    Welcome to TeX.sx! There is no need to add a signature or thanks to the post. Simply upvote answers to show your appreciation for any help. Commented Jan 30, 2013 at 22:12
  • 1
    Don't be sorry, it's a very reasonable question :) Welcome!
    – cmhughes
    Commented Jan 30, 2013 at 22:33
  • 1
    Thank you! I look forward to participating. This resource so far has been tremendously helpful.
    – RobertD
    Commented Jan 30, 2013 at 22:36

1 Answer 1

25

The tufte documentclass loads the titlesec package, so we have immediate access to all of its excellent features.

Indeed, tufte-common.def contains declarations for each of chapter, section and subsection using the titleformat. We can tweak them to give us what we want- in your case, using colorbox to help us. A complete MWE is at the end, but here's the bit that we need for your requirements:

% chapter format
\titleformat{\chapter}%
  {\huge\rmfamily\itshape\color{red}}% format applied to label+text
  {\llap{\colorbox{red}{\parbox{1.5cm}{\hfill\itshape\huge\color{white}\thechapter}}}}% label
  {2pt}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

Note that I've used \llap to push the number into the left margin- you can tweak the horizontal separator as you wish. The tweaks for section and subsection are very similar.

The only other subtlety is that I have used

\setcounter{secnumdepth}{2}

so that we get numbers for all of the section headings (the default value is -1 which turns all the numbers off).

screenshot

\documentclass[a4paper,twoside]{tufte-book}

\usepackage{xcolor} % for colour
\usepackage{lipsum} % just for sample text

% add numbers to chapters, sections, subsections
\setcounter{secnumdepth}{2}

% chapter format
\titleformat{\chapter}%
  {\huge\rmfamily\itshape\color{red}}% format applied to label+text
  {\llap{\colorbox{red}{\parbox{1.5cm}{\hfill\itshape\huge\color{white}\thechapter}}}}% label
  {2pt}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

% section format
\titleformat{\section}%
  {\normalfont\Large\itshape\color{orange}}% format applied to label+text
  {\llap{\colorbox{orange}{\parbox{1.5cm}{\hfill\color{white}\thesection}}}}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

% subsection format
\titleformat{\subsection}%
  {\normalfont\large\itshape\color{blue}}% format applied to label+text
  {\llap{\colorbox{blue}{\parbox{1.5cm}{\hfill\color{white}\thesubsection}}}}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\begin{document}

\chapter{Chapter}
\lipsum[1]
\section{Section}
\lipsum[1]
\subsection{Sub section}
\lipsum[1]

\end{document}
5
  • Note that a bug prevents this to work in titlesec 2.10.1 (solved in 2.10.2) : see tex.stackexchange.com/q/299969/1913 Commented Apr 29, 2016 at 13:46
  • How do I move the box inline with the text? @cmhughes Are you still around =)
    – Mars
    Commented Oct 30, 2018 at 16:56
  • Still here :) follow up questions are fine, but will probably be best as a new question
    – cmhughes
    Commented Oct 30, 2018 at 21:58
  • I had some problems with this code, @cmhughes, can you help me? When i try to put an imagine with the marginfigure environment it gives me an error, something about the margin. Commented Apr 24, 2021 at 16:57
  • Best to ask a follow up question
    – cmhughes
    Commented Apr 24, 2021 at 18:21

You must log in to answer this question.

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