Page Layout ⇒ Make section headings always appear furthest from the spine
Make section headings always appear furthest from the spine
The reason for this is so I can use lilypond-book and section headings to number the songs automatically for me.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- 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¹
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Make section headings always appear furthest from the spine
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
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
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
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}{}