3

I'm trying to create an environment that acts like an acknowledgments or abstract section of a long document: a page with a centered title and slightly narrower text than normal. Also, it should start a short ways below the top of the page.

My attempt so far uses the quotation environment. It works fine for sections that are less than a page, as in the "Abstract" example below, but if the content runs over one page as in the "Acknowledgments" example, an extra page break is inserted before the header. Why is this happening? How can I set this environment up so that it starts below the top of the page, with top/bottom vertical stretching like the MWE has when the content is short, but does something sensible when the content gets longer?

MWE:

\documentclass[11pt]{article}
\usepackage{lipsum}

\newenvironment{pseudochapter}[1]
  {\clearpage
   \vspace*{\stretch{1}}
   \begin{quotation}
   \begin{center} \large \textbf{#1} \\[.7em] \end{center}
  }
  {\end{quotation}
   \vspace*{\stretch{3}}
   \clearpage
  }

\begin{document}

\begin{pseudochapter}{Abstract}
  \lipsum[1]
\end{pseudochapter}

\begin{pseudochapter}{Acknowledgments}
  \lipsum[1-4]
\end{pseudochapter}

\end{document}
  • Can you state the rest of what you want? Why do you have the infinite stretch of 1 vfill before the contents of the environment, and 3 vfill after? What is the intended purpose of them? Also how do you guarantee “it should start a short ways below the top of the page” — looks like with your method, it will start a varying amount from the top of the page, based on how much text is inside (and it's not very meaningful when the text stretches to multiple pages). Usually for the Abstract environment and the like, one wants them to start a fixed distance from the top of the page. – ShreevatsaR Feb 7 '18 at 2:08
  • That was actually inherited from the template I was basing this on. I guess the theory is that it should look sort of balanced on the page, starting a short ways down. I had hoped that when the text went over a page, it would still produce a gap at the top of the first page, just a smaller one. But I guess it could make just as much sense to have a fixed vertical space. Is a fixed distance in fact the convention? – duncanka Feb 7 '18 at 6:12
  • 1
    Yes I'd say that a fixed distance from the top of the page is the convention. E.g. if you put two such “Abstract” pages together, they should line up. (And if you have fixed distances, the problem goes away AFAICT…) – ShreevatsaR Feb 7 '18 at 6:22
1

This proposal is quite likely some overkill. It is mainly to advertise the nice macro that allows one to find out whether one is in the first line. It seems to do what you want.

\documentclass[a4paper,12pt]{article}
\usepackage{lipsum}
\usepackage[pagewise]{lineno}
\pagewiselinenumbers
\makeatletter
\def\storepagewiselineno#1{%from https://tex.stackexchange.com/a/413117/121799
    \bgroup % This group is to keep the value of \c@linenumber local
    \testNumberedPage % store the page-wise line number into \c@linenumber
    \expandafter\egroup % smuggle \c@linenumber out of the scope
    \expandafter\edef\expandafter#1\expandafter{\the\c@linenumber}%
}
\makeatother


\def\testinglinenumber{\storepagewiselineno\temp
    \ifnum\temp>1\relax\clearpage\else I am in first line\fi\par
}

\renewcommand\LineNumber{} %turn off showing the line numbers
\newenvironment{pseudochapter}[1]
  {\storepagewiselineno\temp
  \ifnum\temp>1\relax~\clearpage\else\relax\vspace*{\stretch{1}}\fi
\begin{quotation}\interlinepenalty=10000
   \begin{center} \large \textbf{#1} \\[.7em] \end{center}\nobreak
  }
  {\vspace*{\stretch{3}}
  \end{quotation}%
%   \clearpage
}
\begin{document}
\lipsum[1]
\begin{pseudochapter}{Abstract}
  \lipsum[1]
\end{pseudochapter}
\begin{pseudochapter}{Acknowledgments}
  \lipsum[1-4]
\end{pseudochapter}

\end{document}
  • You are excellent user to TeX.SE. +1. – Sebastiano Feb 6 '18 at 9:36
  • I don't understand this answer. The whole \ifnum thing doesn't seem to affect the output; I get exactly the same PDF if I comment it out and replace it with a \clearpage. The point of the \vspace in my original MWE was to push the title a little ways down the page, which doesn't seem to be happening at all with this version. Am I missing something? – duncanka Feb 6 '18 at 17:01
  • @duncanka At least on my TeX distribution I get a 4 page document and if I comment out the \ifnum thing these are only 3. So I don't understand your statement "doesn't seem to affect the output". Other than that, I wrote that the main point here is to make you aware of the \testinglinenumber macro (while hiding the line numbers etc.). I must admit that I was a bit lost when trying to understand your request, and thought that this code would do what you want. – user121799 Feb 6 '18 at 17:14
  • Right, but the MWE has \clearpage, which also gets you 4 pages without the fancy \testinglinenumber thing to get 4 pages. I've edited the original question to hopefully be a bit clearer about what I'm trying to achieve. I realized I put one of the important features only at the bottom of the second paragraph. – duncanka Feb 6 '18 at 22:27

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.