# New environment, orphan line

I created three environments for my document: a booklet for a treasure hunt with scrreprt.

I created 3 environments (the document is in french):

enigma:

\newenvironment{enigme}{\refstepcounter{enigme}\vspace{0.5cm}{\bfseries Énigme \theenigme\ : \\}}{\par\vspace{0.5cm}}


route indications:

\newenvironment{path}{\vspace{0.5cm}{\bfseries \textcolor{DarkBlue}{Parcours :} \\}}{\par\vspace{0.5cm}}


cultural indication:

\newcommand{\culture}[1]{\emph{#1.}}


It works perfectly, but the problem is that sometimes, the words "Énigme" or "Parcours", or the title of my cultural indication are orphan at the end of the page.

What could I do to avoid this? Could I add a test in my \newcommand and \newenvironment? Something like \if@lastlineofpage or something like that...

Of course, I tried the famous

\widowpenalty10000
\clubpenalty10000


and nothing changed. I think the instructions to get rid of my problem should be written inside the \newcommand...

Here's the heading of the document:

\documentclass[12pt,a5paper,twoside=yes]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[pdftex]{graphicx}
\usepackage{lmodern}
\usepackage{subfig}
\usepackage[svgnames]{xcolor}
\usepackage{wrapfig}
\usepackage{fancybox}

• Why don't use theorems like environment from amsthm? You can format it. – Sigur Jun 4 '15 at 8:22
• Welcome to TeX.SX! You should use \addvspace instead of \vspace in these cases; for not breaking after the title, use \\* – egreg Jun 4 '15 at 8:31
• @Patou: See my edit please – user31729 Jun 4 '15 at 10:09
• Thanks to all. I missed the comments of Sigur and egreg because they are smaller. I'm getting a better comprehension on the way this forum works :) – Patrick Augeau Jun 4 '15 at 10:18
• @Patou355: Could you give some feedback for my solution, please? – user31729 Jun 22 '15 at 18:50

The orphane titles can be prevented using box like environments, which allow more design as well and automated counting (something like theorems, as Sigur proposed)

I applied one of my favourite packages -- tcolorbox (No, I am not the author of that package, unfortunately :-()

The colours, frames can be changed at will, as optional argument to the environments. Don't use the breakable specifier either in the option list of the environments, as this could again leave orphane titles etc.

\documentclass[12pt,a5paper,twoside=yes]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[pdftex]{graphicx}
\usepackage{lmodern}
\usepackage{subfig}
\usepackage[svgnames]{xcolor}
\usepackage{wrapfig}
\usepackage{fancybox}

\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter]{enigme}[1][]{title={\bfseries Énigme~\thetcbcounter:},colbacktitle=red,coltitle=black,#1}

\newtcolorbox{path}[1][]{title={\bfseries Parcours:},coltitle=DarkBlue,colbacktitle=yellow,#1}

\newcommand{\culture}[1]{\emph{#1.}}

\begin{document}

\begin{enigme}
Aujourd'hui nous cherchons les chiens ;-)
\end{enigme}

\begin{path}
Nous allons
\end{path}

\culture{Mais oui}

\end{document}


Edit

Now with spacings above and below the boxes, as well with no frames, to show the usage of the optional argument.

\documentclass[12pt,a5paper,twoside=yes]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage[pdftex]{graphicx}
\usepackage{lmodern}
\usepackage{subfig}
\usepackage[svgnames]{xcolor}
\usepackage{wrapfig}
\usepackage{fancybox}

\usepackage[most]{tcolorbox}

\newtcolorbox[auto counter]{enigme}[1][]{enhanced,title={\bfseries Énigme~\thetcbcounter:},before skip=0.5cm,after skip=0.5cm,colbacktitle=red,coltitle=black,#1}

\newtcolorbox{path}[1][]{enhanced,title={\bfseries Parcours:},coltitle=DarkBlue,colbacktitle=yellow,before skip=1.5cm, after skip=2cm,#1}

\newcommand{\culture}[1]{\emph{#1.}}

\begin{document}

\begin{enigme}
Aujourd'hui nous cherchons les chiens ;-)
\end{enigme}

\begin{path}
Nous allons
\end{path}

\culture{Mais oui}

\begin{enigme}[colback=green,breakable]
Aujourd'hui nous cherchons les chats ;-)
\end{enigme}

\begin{path}[colback=white,colbacktitle=white,coltitle=black,frame hidden]
Avant la maison
\end{path}

\end{document}


Next edit

According to the OP's request to have a counter of its own and to let it start from zero, use

\newcounter{enigme}

\setcounter{enigme}{-1}

\newtcolorbox[use counter=enigme]{enigme}[1][]{enhanced,title={\bfseries Énigme~\thetcbcounter:},before skip=0.5cm,after skip=0.5cm,colbacktitle=red,coltitle=black,#1}


\newtcolorbox[auto counter]{enigme}[1][]{enhanced,title={\bfseries Énigme~\thetcbcounter:},before skip=0.5cm,after skip=0.5cm,colbacktitle=red,coltitle=black,#1}