Advertisement
Guest User

section-protegee

a guest
Sep 19th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 0.69 KB | None | 0 0
  1. \documentclass{report}
  2. \usepackage[frenchb]{babel}
  3. \usepackage{lipsum}
  4. \usepackage{environ,calc,needspace}
  5. \newlength\psectiontotheight
  6. \NewEnviron{psection}[1]{%
  7.   \settototalheight{\psectiontotheight}{%
  8.     \begin{minipage}{\textwidth}
  9.      \section{#1}
  10.      \BODY
  11.    \end{minipage}%
  12.   }%
  13.   \ifdim\psectiontotheight>\textheight
  14.   \else
  15.   \needspace{\psectiontotheight}%
  16.   \fi
  17.   \addtocounter{section}{-1}%
  18.   \section{#1}
  19.  \BODY
  20. }{}
  21. \begin{document}
  22. \chapter{}
  23.  
  24. \begin{section}{Première section}
  25. \lipsum[1-2]
  26. \end{section}
  27.  
  28. \begin{psection}{Deuxième section}
  29. \lipsum[1]
  30. \end{psection}
  31.  
  32. \begin{section}{Troisième section}
  33. \lipsum[1-5]
  34. \end{section}
  35.  
  36. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement