Page LayoutMake section headings always appear furthest from the spine

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Make section headings always appear furthest from the spine

Post by bombcar »

I'm using \documentclass{book} and would like to have the \section headings always be away from the binding, i.e, on the left on even pages and flush right on odd pages. I tried using sectsty and titlesec but couldn't figure out how to flush outward depending on the page.

The reason for this is so I can use lilypond-book and section headings to number the songs automatically for me.

Recommended reading 2024:

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

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

Megan
Posts: 6
Joined: Wed Mar 04, 2009 10:48 pm

Make section headings always appear furthest from the spine

Post by Megan »

Try fancyhdr and check out the manual for how to use it.

Minimalist I know but I hope it helps :)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Make section headings always appear furthest from the spine

Post by localghost »

Megan wrote:Try fancyhdr and check out the manual for how to use it. [...]
I think the request is not about positioning the headers, but more the headings. In this case the titlesec package would be a better help.


Best regards
Thorsten¹
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Re: Make section headings always appear furthest from the spine

Post by bombcar »

I tried using titlesec which seems that it should be able to do what I want, but I couldn't figure it out.

What I'm looking for is:

SectionNumberLeft {Section Title, Centered}

on left pages, and:

{Section Title, Centered} SectionNumberRight

on even pages.
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Make section headings always appear furthest from the spine

Post by bombcar »

I've gotten closer (I found how to center the section headings) but I can't get the Section number to move to the left/right depending on even/odd page.

Here's what I have (titlesec didn't work because it somehow broke my \songsection command}:

Code: Select all

%!TEX TS-program = Lilypond-LaTeX
\documentclass[b5paper]{book}
\usepackage{vmargin}        % This package is used to easily set the margins
\usepackage{sectsty}

\sectionfont{\centering}

% The following set the paper size (to match the documentclass) and the margins

\setpapersize{B5}
\setmargnohfrb{15mm}{8mm}{10mm}{8mm}

% The following create some commands to simplify the document:

\newcommand{\songinfo}[4]{\noindent #1 \hfill #2\\
#4 \hspace*{\fill} \textsc{#3}\\}

% \songinfo{Poet}{Composer}{Music}{Copyright}

\makeatletter
\newcommand{\makesongs}{%
  \makeindex
  \bgroup
     \def\indexsection\numberline##1##2\endindexsection{%
       \protected@write\@indexfile{}{\string\indexentry{##2}{##1}}}%
     \def\contentsline##1##2##3{\indexsection##2\endindexsection}%
     \@input@{\jobname.toc}%
  \egroup
}

\newcommand{\listofsongs}{%
\begingroup
  \@input@{\jobname.ind}%
  \if@filesw
    \expandafter\newwrite\csname tf@toc\endcsname
    \immediate\openout\csname tf@toc\endcsname\jobname.toc\relax
  \fi
  \@nobreakfalse
\endgroup}

\newcommand*{\songsection}[2][]{%
  \def\thesongtitle{#1}%
  \ifx\thesongtitle\@empty
    \section{#2}%
  \else
    \section[#1@#2]{#2}%
  \fi
}
\makeatother

% The following redefines the \section command to suppress the chapter numbers

\renewcommand\thesection{\arabic{section}} 

\raggedbottom

\makesongs

\begin{document}

\listofsongs

\newpage
\songsection{A Song Title}
\songinfo{A Poet}{A Composer}{A Music}{\copyright 1042 Music}

\newpage
\songsection{Another Song Title}
\songinfo{Another Poet}{Another Composer}{Another Music}{\copyright 1452 Music}

\end{document}
This is made (and needs makeindex with a file containing:

Code: Select all

preamble "\\section*{Songs}"
postamble ""
group_skip ""
item_0 "\n\\contentsline\{section\}\{"
delim_0 "\}\{"
delim_t "\}"
headings_flag 0
level '>'
to work - and it does, except I can't move the section number. I experimented with redefining @seccntformat as suggested in the sectsty package, but couldn't get it to do what I want.

(Note - this is for LilyPond-book but the above example works fine with LaTeX alone).
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Make section headings always appear furthest from the spine

Post by bombcar »

I finally figured out how to use the titlesec package, and this gets closer to what I want:

Code: Select all

\usepackage{titlesec}
\titleformat{name=\section,page=even}[runin]
        {\normalfont\Large\bfseries}{\thesection}{1em}{\hfill}[\hspace*{\fill}\\ ]
\titleformat{name=\section,page=odd}[runin]
        {\normalfont\Large\bfseries}{}{1em}{\hfill}[\hspace*{\fill}\thesection\\ ]
\titleformat{name=\section,numberless=true,page=odd}[block]
        {\normalfont\Large\bfseries\center}{}{0pt}{}
\titleformat{name=\section,numberless=true,page=even}[block]
        {\normalfont\Large\bfseries\center}{}{0pt}{}
It's probably incorrect, but it works. The only issue I see is the \hfills are not perfectly centering the section heading; but it's close enough.
bombcar
Posts: 22
Joined: Tue Oct 28, 2008 10:18 pm

Make section headings always appear furthest from the spine

Post by bombcar »

This is what I finalized on:

Code: Select all

\titleformat{name=\section,page=even}[runin]
        {\normalfont\Large\bfseries}{\makebox[0pt][l]{\thesection}}{0pt}{\hfill}[\hspace*{\fill}\\]
\titleformat{name=\section,page=odd}[runin]
        {\normalfont\Large\bfseries}{}{0pt}{\hfill}[{\hspace*{\fill}\makebox[0pt][r]{\thesection}}\\]
\titleformat{name=\section,numberless=true,page=odd}[block]
        {\normalfont\Large\bfseries\center}{}{0pt}{}
\titleformat{name=\section,numberless=true,page=even}[block]
        {\normalfont\Large\bfseries\center}{}{0pt}{}
\makebox[0pt] was the key.
Post Reply