I use macro and titlesec
package to create custom \section
heading.
\documentclass[final]{book}
\usepackage{lipsum}
\usepackage{titlesec}
\titlespacing*{\section}{0pt}{1em}{0.3em}
\def \mysection#1{
\section*{\large{#1}}
}
\begin{document}
\mysection{Lorem ipsum dolor sit amet, consectetur adipisicing elit doloribus odio aliquid aut.}
\lipsum[2]
\mysection{Another section heading with very long text within it that wraps to second line}
\lipsum[3]
\end{document}
which produces
I want to be able to decrease or increase line spacing between lines of that \section
heading.
I have tried to do so, by changing \mysection
macro to:
\def \mysection#1{
\section*{\baselineskip=2pt \large{#1}}
}
but it doesn't have any effect. (Note that I set \baselineskip
to 2pt
only to spot it for sure when change happens, not because it is my target line spacing).
I have also tried to change it to:
\def \mysection#1{
\section*{\linespread{0.1} \large{#1}}
}
which seems to have slight effect on line spacing, but produces nasty indent out of nowhere:
I have also tried using setspace
package with its command \singlespacing
:
\documentclass[final]{book}
\usepackage{lipsum}
\usepackage{titlesec}
\usepackage{setspace}
\titlespacing*{\section}{0pt}{1em}{0.3em}
\def \mysection#1{
\section*{\singlespacing \large{#1}}
}
\begin{document}
\mysection{Lorem ipsum dolor sit amet, consectetur adipisicing elit doloribus odio aliquid aut.}
\lipsum[2]
\mysection{Another section heading with very long text within it that wraps to second line}
\lipsum[3]
\end{document}
which decreases line spacing, but adds unexpected white space above \section
headings:
Is there any reliable way to modify line spacing of \section
headings? I thought that titlesec
should be able to do it, but I haven't found a clue how to do it in its documentation.
Best Answer
You can use
\titleformat
in thetitlesec
package to control the format of the section headings:From the manual, the syntax for the
\titleformat
command is:specifying, in order, the title command to modify, the optional "shape" of the title (display/block/...), the format of title, the horizontal length between label and title, and code to execute before and after the title body.
The example above emulates the standard section title.