Page Layoutchapter first page special layout

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
jafar
Posts: 4
Joined: Wed Sep 22, 2010 7:46 am

chapter first page special layout

Post by jafar »

The attached picture shows a chapter layout that I have been trying to achieve in latex. The major feature causing me difficulty is the chapter title on the left of the page in a vertical bar. This bar should appear only on the first page of the chapter, and should be within the \textwidth.

I have attempted the following code to achieve this:

Code: Select all

\documentclass[a4paper,openany]{amsbook}

\usepackage{color}
\usepackage{array}
\usepackage{colortbl}
\usepackage{rotating}

\definecolor{Dark}{gray}{.20}
\definecolor{Light}{gray}{.40}

\makeatletter
\renewcommand{\@makechapterhead}[1]{%
\vspace*{50 pt}%
{\setlength{\parindent}{0pt} \raggedright \normalfont
\bfseries\Large
\begin{tabular}{|>{\color{white}\columncolor[gray]{.2}}r|>{\color{white}%
\columncolor[gray]{.6}}p{11cm}}
\thechapter & #1
\end{tabular}

\begin{sideways}\colorbox{Dark}{\color{white}\thechapter}\ \colorbox{Light}{\color{white}#1}\end{sideways}

\par\nobreak\vspace{40 pt}}}
\makeatother

\begin{document}

\chapter{XYZ}

\section{Introduction}
Body text here

\end{document}
It has the following issues:
1) The vertical bar does not span the whole page.
2) The main text does not start to the right of the vertical bar.

How can I achieve the desired layout?

Thanks
Attachments
image of desired chapter first page
image of desired chapter first page
chapterfirstpage.jpg (118.32 KiB) Viewed 4034 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

chapter first page special layout

Post by nlct »

You could use my flowfram package:

Code: Select all

\documentclass[a4paper,openany]{amsbook}

\usepackage{calc}
\usepackage{flowfram}
\usepackage{lipsum}
\usepackage{mathptmx}

\definecolor{Dark}{gray}{.40}
\definecolor{Light}{gray}{.60}

\onecolumn

% Lengths to be adjusted as required

% Width of block containing chapter number
\newlength\numblockwidth
\setlength{\numblockwidth}{1cm}

% Height of chapter heading bar

\newlength\headbarheight
\setlength{\headbarheight}{1cm}

\newlength\headbarwidth
\setlength\headbarwidth{\textwidth-\numblockwidth}

% Height gap between chapter heading and text

\newlength\Vgap
\setlength{\Vgap}{5mm}

% Width of left bar

\newlength\leftbarwidth
\setlength{\leftbarwidth}{0.1\textwidth}

% Width of gap between left bar and text

\newlength\Hgap
\setlength{\Hgap}{5mm}

% Height of left bar

\newlength\leftbarheight
\setlength{\leftbarheight}{\textheight-\Vgap-\headbarheight}

% Width remaining for text body on first page of chapter

\newlength\chapbodywidth
\setlength{\chapbodywidth}{\textwidth-\Hgap-\leftbarwidth}

\newlength\offset

% Frames for first page of chapters

\newdynamicframe[none]{\leftbarheight}{\leftbarwidth}{0pt}{0pt}[leftbar]

\setlength{\offset}{\leftbarheight+\Vgap}

\newdynamicframe[none]{\numblockwidth}{\headbarheight}
  {0pt}{\offset}[chapnum]

\newdynamicframe[none]{\headbarwidth}{\headbarheight}{\numblockwidth}{\offset}[chaphead]

\newflowframe[none]{\chapbodywidth}{\leftbarheight}
  {\leftbarwidth+\Hgap}{0pt}[chapbody]

\setdynamicframe*{chapnum}{textcolor=white,backcolor=black,valign=c}
\setdynamicframe*{chaphead}{textcolor=white,backcolor=Dark,valign=c}
\setdynamicframe*{leftbar}{textcolor=Light,backcolor=Dark,valign=c,angle=90}

\def\thechaptertitle{}
\setdynamiccontents*{chaphead}{\huge\bfseries\thechaptertitle}
\setdynamiccontents*{leftbar}{\centering\fontsize{26pt}{28pt}\selectfont
  \bfseries\thechaptertitle\par}
\setdynamiccontents*{chapnum}{\centering\huge\bfseries\thechapter\par}

\newcount\nextpage

\makeatletter
\let\orgchap\chapter
\def\chapter{%
  \nextpage=\c@page
  \advance\nextpage by 1\relax
  \xdef\thispage{\number\nextpage}%
  \setdynamicframe*{chapnum,chaphead,leftbar}{pages=\thispage}%
  \setflowframe*{chapbody}{pages=\thispage}%
  \setflowframe{1}{pages={<\thispage,>\thispage}}%
  \clearpage
  \@afterindentfalse
  \secdef\@chapter\@schapter
}%
\def\@makechapterhead#1{\def\thechaptertitle{#1}\par}
\makeatother

\title{A Sample Document}
\author{A.N. Author}
\begin{document}
\maketitle

\chapter{Academic Plan}

\lipsum

\end{document}
The package is a bit on the fragile side as it has to do some fairly complicated stuff, so it can get easily broken. If a paragraph spans a break between two columns/pages of unequal text width you need to put \framebreak at the point where the break occurs. For example, in the above code, the text in the second page of the chapter doesn't reach the end of the text block.

Regards
Nicola Talbot
jafar
Posts: 4
Joined: Wed Sep 22, 2010 7:46 am

Re: chapter first page special layout

Post by jafar »

It looks beautiful, except manually inserting \framebreak is a deathblow because it will make it inflexible to modifications, and automatic formatting is the main reason for using latex, at least for me. I suppose if no better solutions are coming, I might consider moving the leftbar outside the textwidth margin (or effectively, making the text be in the same frame throughout the document). I'll study the code more to figure out how to do that, unless you are feeling generous and want to do it for me ;) . Either way, thanks a lot... it is going to help me make a lot of progress.
jafar
Posts: 4
Joined: Wed Sep 22, 2010 7:46 am

Re: chapter first page special layout

Post by jafar »

My solution was to relax the requirements, moving the leftbar out of the textwidth so that the amount of width that the chapter body gets remains constant throughout the document.
Post Reply