我想写一个\begin{myFramedBox} ... \end{myFramedBox}
这样的命令:
- 如果里面的块
\begin{myFramedBox} ... \end{myFramedBox}
位于页面的开头,那么就会正常打印。 - 否则:它将上面打印一条规则。
这些命令允许我拥有由规则分隔的块,除非有分页符。
怎么做?(我愿意接受解决方案tcolorbox
)
答案1
使用此处代码的肮脏黑客行为:https://tex.stackexchange.com/a/41302/101651。
如果它对你的情况有用,请告诉我。
\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}