Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've noticed in my document class that when I have really long chapter titles, the title can end up mixing in with the first line of text on the page. My default spacing is 50pt. If I set it higher, to say 150pt, the page with the long chapter name looks fine, but all the rest with single line chapter names have too much white space below it for my taste.

I don't want to have to manually alter the spacing at each chapter... is there a way I can tie the spacing to the size of the minipage that I use for the chapter title?

\documentclass{book}
\let\cleardoublepage\clearpage

\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage[
  left=2.25in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.75in,
  marginparsep=.25in,
  asymmetric]{geometry}

\renewcommand*\familydefault{\sfdefault} % Set default font

\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  %\setcounter{definition}{0}
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
        \node[anchor=north west,xshift=.21\paperwidth,yshift=-.040\paperheight,rectangle]
              {\begin{minipage}{.9\textwidth}
                \color{cyan}\Huge\raggedright\MakeUppercase{#1}
              \end{minipage}};
       \end{tikzpicture}
      };
   \end{tikzpicture}
  }
\makeatother

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

\titleformat{\section}{\color{cyan}\itshape\LARGE}{\llap{\thesection} #1}{1em}{}[\titleline{\color{cyan}\titlerule[1pt]}]
\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}

\begin{document}
  \chapter{A normal chapter}
    \section{A Section}
  \chapter{ON COMPUTABLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHEIDUNGSPROBLEM}
    \section{Another Section}
\end{document}
share|improve this question
add comment

1 Answer

up vote 8 down vote accepted

The normal behaviour would be for latex to leave space, it is the fixed height box that is preventing that. You can take the chapter text out of the box and let it take part in the normal page flow, then the following section head is positioned normally, something like this:

enter image description here

\documentclass{book}
\let\cleardoublepage\clearpage

\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage[
  left=2.25in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.75in,
  marginparsep=.25in,
  asymmetric]{geometry}

\renewcommand*\familydefault{\sfdefault} % Set default font

\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}{0pt}
  {\thispagestyle{empty}    % Remove page number on new chapters
  %\setcounter{definition}{0}
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
       \end{tikzpicture}
      };
   \end{tikzpicture}\endgraf
  \vskip-.7cm
  \color{cyan}\Huge\raggedright\leftskip-1cm
   \noindent\MakeUppercase{#1}\endgraf
  }
\makeatother

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

\titleformat{\section}{\color{cyan}\itshape\LARGE}{\llap{\thesection} #1}{1em}{}[\titleline{\color{cyan}\titlerule[1pt]}]
\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}

\begin{document}
  \chapter{A normal chapter}
    \section{A Section}
  \chapter{ON COMPUTABLE NUMBERS, WITH AN APPLICATION TO THE ENTSCHEIDUNGSPROBLEM}
    \section{Another Section}
\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.