Text FormattingCenter a very long chapter tile

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Mimi
Posts: 5
Joined: Wed Jan 07, 2015 5:40 pm

Center a very long chapter tile

Post by Mimi »

Hello!

Below is my MWE.

Code: Select all

\documentclass{report}

\usepackage{titlesec}
\titleformat{\chapter}[hang]
{\normalfont\normalsize\bfseries\centering}{\chaptertitlename\ \thechapter:}{2mm}{}

\begin{document}
\chapter{The big black bug bit the big black bear, but the big black bear bit the big black bug back!}
\end{document}
I would like to have the second line of the chapter title to be in the center of the page.

Recommended reading 2024:

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

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

User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Center a very long chapter tile

Post by Johannes_B »

Both are typeset in different boxes, so you manually need to break the lines.

Code: Select all

\documentclass{report}

\usepackage{showframe}
\usepackage{titlesec}
\titleformat{\chapter}[hang]
{\normalfont\normalsize\bfseries\centering}{\chaptertitlename\
\thechapter:}{2mm}{}
\newlength{\chapterindent}
\newcommand{\gethalfwidth}{\settowidth{\chapterindent}{\bfseries\chaptertitlename\
\thechapter:}%
\addtolength{\chapterindent}{2mm}
}
\begin{document}
\newcommand{\breakline}{\\\gethalfwidth\hspace{-\chapterindent}\ignorespaces}
\chapter{The big black bug bit the big
	black bear, but the big\breakline
bear bit the big black bug back!}

\setcounter{chapter}{20}
\chapter{The fox, and the duck, and another small animal,
but\breakline also a big red elephant are walking down the road
to\breakline happiness}
\end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Mimi
Posts: 5
Joined: Wed Jan 07, 2015 5:40 pm

Re: Center a very long chapter tile

Post by Mimi »

谢谢你的帮助!
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Center a very long chapter tile

Post by Johannes_B »

If google translate works properly; i respond to that with: No problem ;-)
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply