Text FormattingAvoid figure or page break in a multiple line section title

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
rafaelgoes
Posts: 4
Joined: Fri Mar 23, 2012 7:08 pm

Avoid figure or page break in a multiple line section title

Post by rafaelgoes »

Hi there!

The formating rules for thesis in my university demmands that titles (chapters, sections, subsections...) are like:

<number>
<Section title>

-------------------------------------------------------------------
Example:

1.
First Chapter

text text text text text text text text text text text text text text text text text text text text text text text text text text text text

1.1.
First Section

text text text text text text text text text text text text text text text text text text text text text text text text text text text text
----------------------------------------------------------------

I used the following code:

\titleformat{name=\section}
[display]
{\penalty -5000\singlespacing\Large\arial\bfseries}
{\thesection}


The problem is that sometimes I get figures between the section number and the Section Title, such as:

---------------
1.1.
<figure>
First Section

text text text text text text text text text text text text text text text text text text text text text text text text text text text text
----------------

or even section number and section title in separate pages?

----------------
text text text text text text text text text text text text text text text text text text text text text text text text text text text text

1.1.
======== page break =========
First Section
----------------

Does anybody know how to avoid that?

Thanks in advance!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Avoid figure or page break in a multiple line section title

Post by Johannes_B »

In order to make your question better understandable, provide a minimal working example.
As you already mentioned, your solution doesn't work quite well, but there are better ways. But to think about those, at least the knowledge of the documentclass is needed.

You might also want to take a look at the titlesec-package.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
rafaelgoes
Posts: 4
Joined: Fri Mar 23, 2012 7:08 pm

Avoid figure or page break in a multiple line section title

Post by rafaelgoes »

Follow below the MWE:

Code: Select all

\documentclass{book}%
\usepackage{graphicx}
\usepackage{titlesec}

\newcommand{\autolabel}[1]{\label{sec:#1}#1}
\titleformat{name=\chapter}
	[display]
  {\LARGE\bfseries}
  {\thechapter}
  {0pt}
  {\autolabel}

\titleformat{name=\section}% Rafael Goes 25/04/2013
	[display]
  {\penalty -5000\Large\bfseries}
  {\thesection}
  {0pt}
  {\autolabel}

\begin{document}

\chapter{First Chapter}

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate.

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate.

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. 

\section{First section}

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. 

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. 

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. 

\begin{figure}[htbp]
	\centering
		\includegraphics[width=0.5\textwidth]{smiley-face.jpg}
	\caption{This is a figure}
	\label{fig:smiley-face}
\end{figure}

\section{Second section}

This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. This is a generic text just to illustrate. 

\end{document}
Last edited by cgnieder on Mon Jul 22, 2013 10:48 am, edited 1 time in total.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Avoid figure or page break in a multiple line section title

Post by Johannes_B »

It seems, that this is somehow related to your autolabel-command.
Try this:

Code: Select all

\newcommand{\autolabel}[1]{#1\label{sec:#1}}
Just as a remark, chapters and sections are labeled with the prefix sec:. Be careful, you might get confused when your project is growing.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
rafaelgoes
Posts: 4
Joined: Fri Mar 23, 2012 7:08 pm

Re: Avoid figure or page break in a multiple line section ti

Post by rafaelgoes »

It worked!
Totally solved the problem!
Thanks a lot!
Post Reply