0

I defined one command to chect the current page number, if odd page then show odd page objects, else show even page objects, the codes from original question, and changed from it.

But I found one problem, when I use many times \oddeven in one odd page, if the current page can't contain it at page bottom, it will be float to the new page (even page), that is say, even page have odd page object, I don't know how to sove it.

\documentclass{article}
\usepackage[strict]{changepage}
\usepackage{float}
\newcommand*{\oddeven}{\checkoddpage\ifoddpage \par \rule{10cm}{4cm}\par\vspace{3mm} \else EVEN page \fi}

\begin{document}

\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven

\end{document}

enter image description here

zongxian
  • 467
  • 2
    If your content is too large for the page it gets broken to the next page. Isn't that the purpose of using LaTeX? – Henri Menke Jun 17 '18 at 06:54
  • @HenriMenke I think you are right, but how to know it is too large for the page, is there command can check. – zongxian Jun 17 '18 at 06:58
  • There are two registers, \pagetotal contains the vertical space that is already occopied, \pagegoal the total vertical space of the page, i.e. to obtain the available space, subtract them \dimexpr\pagegoal-\pagetotal\relax. – Henri Menke Jun 17 '18 at 07:03
  • The main problem is that the content for the odd page is much larger than the one for the even page. Is this also the case in your real document? – Ulrike Fischer Jun 17 '18 at 10:10
  • @UlrikeFischer It is simple codes, real document just different, odd page figure1 and even page figure2. – zongxian Jun 17 '18 at 10:16
  • If the left page code and the right page code have the same size your code could work (but you will have to move the \checkoddpage command. If they have different size much more complicated checks are needed. – Ulrike Fischer Jun 17 '18 at 10:22

1 Answers1

1

To prevent the page break just insert infinite penalties after \par using \nobreak and enjoy your overfull vboxes.

\documentclass{article}
\usepackage[strict]{changepage}
\usepackage{float}
\newcommand*{\oddeven}{%
  \checkoddpage
  \ifoddpage
    \par\nobreak
    \rule{10cm}{4cm}%
    \par\nobreak
    \vspace{3mm}%
  \else
    EVEN page%
  \fi
}

\begin{document}

\newpage
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven
\oddeven

\end{document}

enter image description here

Henri Menke
  • 109,596