Text FormattingNested list first item on another page

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
kulima
Posts: 23
Joined: Mon Aug 03, 2015 5:42 pm

Nested list first item on another page

Post by kulima »

Hi

I have a itemize list nested in my description list. My Problem is that the page ends right when the itemize list begins, so at the bottom of the page i got my last description(Item 23) and the first itemized item("First nested Item" is on the top of the page.
Now i want to keep "Item 23" on the same page as the nested list. It#s a bit hard to explain, here is a code example of how it looks like. Please ignore the "Random Text" and \bigskips, they are just there to push the items down and illustrate the problem.

Code: Select all

\documentclass[12pt,a4paper,headsepline]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[naustrian]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[automark]{scrlayer-scrpage}
\usepackage{blindtext}
%\usepackage{scrletter}
\begin{document}
\blindtext
\blindtext[2]
Random Text

\bigskip
Random Text

\bigskip
Random Text

\bigskip
Random Text

\bigskip
Random Text



\begin{description}
	\item[Item 1] \hfill \\
    	Some text
    \item[Item 2] \hfill \\
    	Some more text
    \item[Item 23] \hfill
    \begin{itemize}
    	\item First nested Item
        \item Second nested Item
    \end{itemize}
    \item[Item 24] \hfill \\
    	Last Item text
\end{description}
\end{document}
Now i could quickfix it with \newpage or \bigskip or whatever, but that presents a whole lot of new problmes once i change the document. Is there an (easy) solution to keep nested lists with its parent item, or at least one of the nested items, or push "Item 23" to the next page, so "Item 23" does not look so lonely on the bottom of the page?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Nested list first item on another page

Post by Stefan Kottwitz »

You could load the needspace package:

Code: Select all

\usepackage{needspace}
Then, wherever needed, you can require space. If there's not enough space left on the page, the following text would go to the next page:

Code: Select all

\needspace{2\baselineskip}\item[Item 23]
It can be automatized for each \item, but I would not do this as \item is implicitly used at many places.

Stefan
LaTeX.org admin
kulima
Posts: 23
Joined: Mon Aug 03, 2015 5:42 pm

Re: Nested list first item on another page

Post by kulima »

Works like a charm.
Thanks
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Nested list first item on another page

Post by Stefan Kottwitz »

Nice to read your confirmation! I also tested it with your code. You provided a very good minimal code example, so it was easy.

I see you are using naustrian. If you like to post in Austrian or German language, feel free to visit our partner forum TeXwelt.de too.

A matching topic is already there: "Wie kann ich in enumerate und itemize für jedes item extra-Code ausführen lassen?"

We love good questions, here and there. :)

Stefan
LaTeX.org admin
kulima
Posts: 23
Joined: Mon Aug 03, 2015 5:42 pm

Re: Nested list first item on another page

Post by kulima »

Good to know! Although i am quiet happy with the services provided here ;-)
Post Reply