6

I'm using tabularx to make a nice chapter title (probably not the way to go, but the easiest for me to align stuff).

  1. How do I make the title line spacing equal? (The letter "g" messes up the spacing), also why is the title not horizontally aligned?

  2. Is there a better way to achieve this effect without using tabularx? Big chapter number on the right aligned at the bottom, while the title is underlined and multilined?

\documentclass{book}

\usepackage{xcolor} 


\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{tabularx}

\newcolumntype{L}{>{\raggedleft\arraybackslash}X}

\renewcommand\tabularxcolumn[1]{b{#1}} 

\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{
\begin{tabularx}{\linewidth}{@{}L r@{}} 
{\Huge \sffamily \textbf {#1}}\vspace{0.2em} & 
{\normalfont\sffamily\fontsize{120}{110}\selectfont\color{gray!25}{\textbf \thechapter}} \\\cline{1-1}
\end{tabularx}
}

\begin{document}

\chapter{ace ace ace ace ace ace ace age ace ace ace ace ace ace ace }

\end{document}

enter image description here

2
  • 1
    you should put the \Huge before the \begin{tabular} so that the standard line spacing fits. – Ulrike Fischer Jul 6 '20 at 7:07
  • this is unrelated to tabular {\Huge \sffamily \textbf {#1}} sets Huge text on a nornalsize baseline as you end the size xhange with } before the end of the paragraph – David Carlisle Jul 6 '20 at 7:17
6

I suggest you change

\begin{tabularx}{\linewidth}{@{}L r@{}} 
{\Huge \sffamily \textbf {#1}}\vspace{0.2em} & 

to

\begin{tabularx}{\linewidth}{@{} >{\Huge\sffamily\bfseries}L r @{}} 
#1 & 

A full MWE:

enter image description here

\documentclass{book}
\usepackage{xcolor} 

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

\usepackage{tabularx}
\newcolumntype{L}{>{\raggedleft\arraybackslash}X}
\renewcommand\tabularxcolumn[1]{b{#1}} 

\titleformat{\chapter}[block]
{\normalfont\sffamily}{}{0pt}
{
%\begin{tabularx}{\linewidth}{@{}L r@{}} 
%{\Huge \sffamily \textbf {#1}}\vspace{0.2em} & 
\begin{tabularx}{\linewidth}{@{} >{\Huge\sffamily\bfseries}L r @{}} 
#1 & 
{\normalfont\sffamily \fontsize{120}{110}\selectfont \color{gray!25}{\textbf \thechapter}} \\\cline{1-1}
\end{tabularx}
}

\begin{document}
\chapter{ace ace ace ace ace ace ace age ace ace ace ace ace ace ace}
\end{document}
6

I'd not use tabularx, but a top aligned \parbox that contains a bottom aligned \parbox with the title, the vertical skip and the rule. This way the chapter number will be aligned with the bottom line of the title.

\documentclass{book}

\usepackage{xcolor} 
\usepackage{showframe} % just for the example

\usepackage{titlesec}
\usepackage{lmodern}


\titleformat{name=\chapter}[block]
  {\normalfont\sffamily}
  {}
  {0pt}
  {\jakechapter{\thechapter}}

\titleformat{name=\chapter,numberless}[block]
  {\normalfont\sffamily}
  {}
  {0pt}
  {\jakechapter{\hphantom{0}}}

\newsavebox{\jakechapterbox}
\newcommand{\jakechapter}[2]{%
  \sbox{\jakechapterbox}{\normalfont\fontsize{120}{110}\sffamily\bfseries\color{gray!25}#1}%
  \parbox[t]{\dimexpr\textwidth-\wd\jakechapterbox-2\tabcolsep}{%
    \parbox[b]{\linewidth}{%
      \raggedleft\normalfont\Huge\sffamily\bfseries#2%
    }
    \vspace{0.2em}\hrule
  }\hfill\usebox{\jakechapterbox}%
}


\begin{document}

\begingroup\let\clearpage\relax\let\cleardoublepage\relax

\chapter*{Introduction}

\chapter{This is a chapter title split across two lines}

\endgroup

\end{document}

The \begingroup...\endgroup business is for producing a single image with two chapter titles, one numbered and the other unnumbered.

The second picture shows that the baselines of the title and of the chapter number agree.

enter image description here

enter image description here

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.