1

I would like to write a command \begin{myFramedBox} ... \end{myFramedBox} such that:

  • If the block inside \begin{myFramedBox} ... \end{myFramedBox} is at the beginning of the page, then it is printed normally.
  • Else: it is printed with a rule above it.

These commands would allow me to have blocks that are separated by rules unless there is a pagebreak.

How to do that? (I'm open to solution with tcolorbox)

1
  • \pagetotal should be 0pt at the top of a page, but it is only changed between paragraphs. Dec 23, 2021 at 15:28

1 Answer 1

1

A dirty hack using the code from here: https://tex.stackexchange.com/a/41302/101651.

Let me know if it works in your case.

\documentclass{book}
\usepackage{mwe}% <--- For testing purpose only
\usepackage{etoolbox}
\usepackage{xcolor}
\usepackage[mathlines]{lineno}
%Code from: https://tex.stackexchange.com/a/41302/101651
\renewcommand\linenumberfont{\color{white}}
\makeatletter
\@addtoreset{linenumber}{page}
\makeatother
\newenvironment{myFramedBox}
    {\ifnumequal{\thelinenumber}{0}{}{\vspace{10pt}\hrule\vspace{10pt}}}{\par}
\begin{document}\linenumbers
\blindtext
\begin{myFramedBox} 
This has a rule above 
\end{myFramedBox}
\blindtext\newpage
\begin{myFramedBox} 
This has no rule above 
\end{myFramedBox}
\blindtext
\begin{myFramedBox} 
This has a rule above 
\end{myFramedBox}
\newpage
\begin{myFramedBox} 
This has no rule above 
\end{myFramedBox}
\blindtext
\end{document}

enter image description here

6
  • Thanks! I will try in the coming days and let you know.
    – Colas
    Dec 24, 2021 at 10:52
  • 1
    @Colas You're welcome! I hope it works.
    – CarLaTeX
    Dec 24, 2021 at 11:08
  • Hi CarLaTeX. Unfortunately, it does not work. Thanks again anyway!
    – Colas
    Dec 25, 2021 at 12:41
  • @Colas What error/anomaly does it gives you?
    – CarLaTeX
    Dec 25, 2021 at 12:55
  • It's difficult to know because I've copied/pasted your solution in my document. Basically, the majority of the text disappears!
    – Colas
    Dec 25, 2021 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.