Page Layout ⇒ Make section headings always appear furthest from the spine
Make section headings always appear furthest from the spine
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.
The reason for this is so I can use lilypond-book and section headings to number the songs automatically for me.
NEW: TikZ book now 40% off at Amazon.com for a short time.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Make section headings always appear furthest from the spine
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.Megan wrote:Try fancyhdr and check out the manual for how to use it. [...]
Best regards
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Make section headings always appear furthest from the spine
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.
What I'm looking for is:
SectionNumberLeft {Section Title, Centered}
on left pages, and:
{Section Title, Centered} SectionNumberRight
on even pages.
Make section headings always appear furthest from the spine
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}:
This is made (and needs makeindex with a file containing:
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).
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}
Code: Select all
preamble "\\section*{Songs}"
postamble ""
group_skip ""
item_0 "\n\\contentsline\{section\}\{"
delim_0 "\}\{"
delim_t "\}"
headings_flag 0
level '>'
(Note - this is for LilyPond-book but the above example works fine with LaTeX alone).
Make section headings always appear furthest from the spine
I finally figured out how to use the titlesec package, and this gets closer to what I want:
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.
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}{}
Make section headings always appear furthest from the spine
This is what I finalized on:
\makebox[0pt] was the key.
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}{}