1

I have a specific kind of text. It looks like a big paragraph from several lines and than goes one another paragraph on one line (and consists of one reference to a link). But the text is too big, so there are situation, when a paragraph stays on one page and only another paragraph (link) goes to another one.

The most wonderful situation would be if on the next page transfered the last line of big pharagraph and a paragraph-link. Is it possible to do that?

P.S. It's not "Widows and orphans". They are two different paragraphs.

It looks like this:

In consideration of the day and hour of my birth, it was declared by the nurse, and by some sage women in the neighbourhood who had taken a lively interest in me several months before there was any possibility of our becoming personally acquainted, first, that I was destined to be unlucky in life; and secondly, that I was privileged to see ghosts and spirits; both these gifts inevitably attaching, as they believed, to all unlucky infants of either gender, born towards the small hours on a Friday night.

XXX(link)

But when i have a page break, i can get this:

In consideration of the day and hour of my birth, it was declared by the nurse, and by some sage women in the neighbourhood who had taken a lively interest in me several months before there was any possibility of our becoming personally acquainted, first, that I was destined to be unlucky in life; and secondly, that I was privileged to see ghosts and spirits; both these gifts inevitably attaching, as they believed, to all unlucky infants of either gender, born towards the small hours on a Friday night.

--------New page--------

XXX(link)

The best variant i need looks like this:

In consideration of the day and hour of my birth, it was declared by the nurse, and by some sage women in the neighbourhood who had taken a lively interest in me several months before there was any possibility of our becoming personally acquainted, first, that I was destined to be unlucky in life; and secondly, that I was privileged to see ghosts and spirits; both these gifts inevitably attaching, as they believed, to all unlucky infants of

--------New page--------

either gender, born towards the small hours on a Friday night.

XXX(link)

  • Hello and Welcome to TEX.SX! Could you provide a MWE or at least a picture of your situation? Otherwise it's really hard to understand, what you are trying to accomplish. – Wamseln Aug 7 '17 at 19:49
  • 1
    you can perhaps "pretend" that the link is a math display, and, without a blank line between the paragraph and the link, place the link into a display format: \[ \text{<the link>} \]. this will center the link (like a display), but it will drag the last line of the preceding text onto the following page. – barbara beeton Aug 7 '17 at 19:56
  • 1
    Doesn't \par\nobreak work? – Ulrike Fischer Aug 7 '17 at 20:23
  • 1
    @UlrikeFischer’s hint should yield what you want: if it moves the whole preceding paragraph to the next page, it means that you, or your document class, has changed the default parameters that govern page breaking (have you, by any chance, issued a samepage declaration?). Once again, you need to post the code you are using, or—much better—a MWE. – GuM Aug 7 '17 at 21:09
  • 1
    ...the small hours on a Friday night.\\*[\medskipamount] \textsl{XXX(link)} should also produce the desired result, including some vertical space. – GuM Aug 7 '17 at 21:21
2

Use \par\nobreak\noindent. The example below sets the text height to seven lines, so the seventh line of the main paragraph would fit (it does if \finallink is omitted).

\documentclass{article}

\newcommand{\finallink}[1]{%
  \par\nobreak\noindent#1\par
}

\textheight=7\baselineskip % just for the example

\begin{document}

In consideration of the day and hour of my birth,
it was declared by the nurse, and by some sage women
in the neighbourhood who had taken a lively interest
in me several months before there was any possibility
of our becoming personally acquainted, first, that
I was destined to be unlucky in life; and secondly,
that I was privileged to see ghosts and spirits;
both these gifts inevitably attaching, as they believed,
to all unlucky infants of either gender, born towards
the small hours on a Friday night.
\finallink{David Copperfield, Chapter One}

\end{document}

enter image description here

| improve this answer | |
0

This solution uses a special environment to check if the text will fit on the page and add the link at the bottom of the page. First it checks if there is room for the link and at least one line of text.

It uses tikzpagenodes to calculate how much space is left on the page (takes two runs). Right now it assumes only \parskip between the text and the link.

The \vsplit command is what LaTeX uses to break paragraphs at the end of pages. It is designed to place the last baseline at the bottom of the text area, allowing the descenders to extend below.

Note that environments always use local registers.

\documentclass{article}
\usepackage{tikzpagenodes}
\usepackage{environ}
\usepackage{needspace}
\usepackage{lipsum}% MWE only
\usepackage{showframe}% MWE only

\newlength{\SPsize}

\NewEnviron{splitpar}[1]% #1 = link
 {\setbox0=\vbox{\BODY}%
  \setbox1=\vbox{\hrule height0pt\par#1}% include gap
  \needspace{\dimexpr \baselineskip+\ht1}% check if link will fit at all
  \strut\tikz[remember picture,overlay]{\pgfextracty{\SPsize}{\pgfpointdiff
    {\pgfpointanchor{current page text area}{south}}{\pgfpointorigin}}%
    \global\SPsize=\dimexpr \SPsize+\ht\strutbox\relax}%
  \vspace{-\baselineskip}% will be on separate line
  \ifdim\SPsize<\dimexpr \ht0+\dp0+\lineskip+\ht1\relax
    \setbox2=\vsplit0 to \dimexpr \SPsize-\dp\strutbox-\lineskip-\ht1\relax
    \unvbox2\vfil\unvbox1
    \pagebreak\unvbox0
  \else
    \unvbox0\unvbox1
  \fi
  \par}

\parskip=\baselineskip

\begin{document}
\begin{splitpar}{link goes here}
\lipsum[1-5]
\end{splitpar}

\end{document}
| improve this answer | |

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.