5

I am trying to reproduce a nice chapter title as shown as Less is More in this blog using titlesec:

\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec, blindtext, color}
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\hsp}{0pt}{\Huge\bfseries}
\begin{document}
\chapter{Less is More}
\blindtext
\end{document}

This works 'as advertised', however: when there is a long title, it breaks over 2 or more lines. I would like the vertical bar to scale with the height of the title text.

Instead of going for an automagically resizing solution, I have tried manual solutions where I just adapt the bar by hand in case of a long title. I have tried using \rule instead of |, which allows me to set the height and also the vertical placement of the bar. But then the second line of the title is displaced lower, starting under the bar. To see this, replace the \titleformat line above by

\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{\rule[-25pt]{2pt}{50pt}}\hsp}{0pt}{\Huge\bfseries}

and a use long chapter title spanning multiple lines.

I also tried creating a frame with only the left frame part around the title using the package mdframed, but I was not able to use \begin{mdframed} and \end{mdframed} in conjunction with titlesec. Placing {\begin{mdframed}} in the before-command (see documentation of mdframed) and {\end{mdframed}} in after-command just gave heaps of errors.

How should I approach this problem? I don't have too many chapters so a manual solution would be absolutely fine. Preferentially I would like to learn how to control the position of the broken line, in case of the \rule solution.

  • Just an idea: because the title text is obviously affected by what happens with the bar, can I put the bar and the title in their own box so they don't 'feel' eachother? – J Riverside Apr 28 '16 at 17:36
5

Like this?

\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage{blindtext, array, color}
 \definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\color{gray75}\thechapter}{20pt}{\begin{tabular}[t]{@{\color{gray75}\vrule width 2pt}>{\hsp}l}#1\end{tabular}}

\begin{document}

\chapter{He Who can do the More\\can do the Less}

\blindtext

\end{document} 

enter image description here

If you want to have an automatic line breaking, replace the last line of the code with:

{\begin{tabular}[t]{@{\color{gray75}\vrule width 2pt\hsp}p{0.85\textwidth}}\raggedright#1\end{tabular}}
| improve this answer | |
  • Like that! Except the grey chapter number (can be fixed by removing the first \color{gray75}). Nice solution using the explicit option, but requires manual line breaking. – J Riverside Apr 29 '16 at 10:11
  • The chapter number colour was chosen according to my personal taste… More importantly, yes it requires manual line breaking and it was purposely. What would you think of a title with a long first line and a very short second line? Technically it is easy to have an automatic line breaking (see my updated answer) but I think it's better to have full control on the layout. – Bernard Apr 29 '16 at 10:35
2

Explanation ADDED. Here, I add the macro \barbox as the last thing to do in \titleformat. Then I have to write \barbox, which takes one argument (the chapter header text). What I do is place the chapter-header text into a box named \theCT. The box is a top-aligned \parbox whose width was empirically determined as 55pt less than the document's text width. I made sure to add a \strut to the beginning and end of the text, so that the presence of capital letters and descending letters did not affect how tall the resulting box was... only the number of lines of the box would affect the result.

I then used the depth and height of the box to determine how deep and tall I needed to make the gray rule. Finally, I added the \hsp gap and recapitulated the box containing the chapter-header text.

\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage{titlesec, blindtext, color}
\newsavebox\theCT
\definecolor{gray75}{gray}{0.75}
\newcommand{\hsp}{\hspace{20pt}}
\titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp}{0pt}{\Huge\bfseries\barbox}
\newcommand\barbox[1]{\savebox\theCT{%
  \parbox[t]{\dimexpr\textwidth-55pt}{\strut#1\strut}}%
  \textcolor{gray75}{\rule[-\dp\theCT]{1.1pt}{\dimexpr\ht\theCT+\dp\theCT}}%
  \hsp{\usebox{\theCT}}}
\begin{document}
\chapter{Less is More}
\blindtext
\chapter{Less is More Less is More Less is More Less is More}
\blindtext
\end{document}

enter image description here

| improve this answer | |
  • Works perfectly. Could you explain how this works? – J Riverside Apr 29 '16 at 10:12
  • @JRiverside Thanks. Explanation has been added. – Steven B. Segletes Apr 29 '16 at 10:46
  • I would like to select both solutions as answer, but I selected Bernard's because that is the one I ended up using. Many thanks anyway! – J Riverside May 9 '16 at 13:11
  • @JRiverside That's fine. Thanks for the consideration. Best wishes! – Steven B. Segletes May 9 '16 at 13:13

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.