10

How to start a paragraph from the middle of the page, when something is already written in the first half of the page?

e.g.

\chapter*{Blabla}

\lipsum[1-2]

\gotohalf
\lipsum[3] <- the first line of this paragraph should start from the half of the text height (vertically)

EDIT I don't think that minipage is a solution, because I don't want to modify the look of the chapter header.

1
  • 1
    By middle you mean precisely 0.5 of text height or you are talking in a general fashion?
    – Pouya
    Apr 7, 2014 at 10:34

3 Answers 3

7

\pagegoal, \pagetotal

\pagegoal is a internal register that contains the height that needs filling, \pagestotal is the amount that is already filled.

Example:

\documentclass[a4paper]{report}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{lipsum}

% Put a line in the middle of text height for testing
\usepackage{atbegshi,picture}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(0,\dimexpr-\topmargin-1in %
                   -\headheight-\headsep
                   -.5\textheight\relax){%
      \line(1,0){\paperwidth}%
    }%
  }%
}

\newcommand*{\gotohalf}{%
  \par
  \begingroup
    \dimen0=\pagegoal
    \advance\dimen0 by -\pagetotal
    \advance\dimen0 by -.5\textheight
    \ifdim\dimen0<0pt %
      % space left is smaller than half the text height
      \newpage
      \setlength{\topskip}{0pt}%
      \vspace*{.5\textheight}%  
      \vspace{-\parskip}%
    \else
      \vspace{\dimen0}%
    \fi
  \endgroup
}

\begin{document}
  \chapter*{Blabla}
  \lipsum[1]

  \gotohalf
  \lipsum[3]
\end{document}

Result

However there are severe limitations:

  • LaTeX's output routine works asynchronous, the current values of \pagegoal/\pagetotal might not be too accurate. At the starting page of a chapter it might work.
  • Stuff at the bottom (e.g. float objects) are not taken into account thus the middle moves up.

Package zref-savepos

\pdfsavepos can be used to record the current position and is supported by many TeX compilers (pdfTeX, LuaTeX, XeTeX; both modes PDF and DVI). The page position can be stored in the .aux file and used in the next LaTeX run. Thus at least two LaTeX runs are necessary.

Package zref-savepos adds a user interface to \pdfsavepos:

\documentclass[a4paper]{report}
\usepackage[margin=1in,showframe]{geometry}
\usepackage{lipsum}

% Put a line in the middle of text height for testing
\usepackage{atbegshi,picture}
\AtBeginShipout{%
  \AtBeginShipoutUpperLeft{%
    \put(0,\dimexpr-\topmargin-1in %
                   -\headheight-\headsep
                   -.5\textheight\relax){%
      \line(1,0){\paperwidth}%
    }%
  }%  
}   

\usepackage{zref-savepos}

% Counter gotohalf helps creating unique label names for `\gotohalf
\newcounter{gotohalf}
\renewcommand*{\thegotohalf}{gotohalf\the\value{gotohalf}}
\newcommand*{\gotohalf}{%
  \par
  \stepcounter{gotohalf}%
  \zsaveposy{\thegotohalf}%
  \begingroup
    \dimen0=\dimexpr.5\textheight
      -\zposy{top}sp %
      +\zposy{\thegotohalf}sp %
      -\parskip
    \relax
    \ifdim\dimen0<0pt %
      \newpage
      \vspace*{\dimexpr.5\textheight-\topskip-\parskip\relax}%
    \else
      \kern\dimen0 %
    \fi
  \endgroup
}

\begin{document}
  \zsaveposy{top}% one label at the top of a one page
                 % used as position reference for the top of textheight
  \chapter*{Blabla}
  \lipsum[1-2]

  \gotohalf
  \lipsum[3]
\end{document}

Result

1
  • I had to lecture, so I couldn't say “use \pagetotal”. :-( :-)
    – egreg
    Apr 7, 2014 at 15:20
4

Set a box as high as half the text height; some little adjustments must be added:

\documentclass{article}
\usepackage[pass,showframe]{geometry}
\usepackage{lipsum}

\begin{document}
\vspace*{-\topskip}\vspace{-\baselineskip}% some backing up
\noindent
\begin{minipage}[t][.5\textheight][s]{\textwidth}
\centering
\vspace*{\fill}
{\Large Title\\}
\vspace{4ex}
{\large Author\\}
\vspace*{\fill}
\end{minipage}\par\nointerlineskip % pretend the previous box has no depth

\lipsum

\end{document}

enter image description here

If you want to use the usual headers (or customized with titlesec or other package), just define a new environment:

\documentclass{book}

\usepackage{xparse}

\usepackage[pass,showframe]{geometry} % to show page frames
\usepackage{lipsum} % mock text

\NewDocumentEnvironment{Chapter}{som}
 {%
  \cleardoublepage
  \vspace*{-\topskip}\vspace{-\baselineskip}% some backing up
  \noindent
  \begin{minipage}[t][.5\textheight][s]{\textwidth}
  \IfBooleanTF{#1}
    {\chapter*{#3}}
    {%
     \IfNoValueTF{#2}
       {\chapter{#3}}
       {\chapter[#2]{#3}}
    }%
  \begin{quotation}\small
 }
 {%
  \end{quotation}
  \vspace*{\fill}
  \end{minipage}\par\nointerlineskip % pretend the previous box has no depth
 }

\begin{document}

\begin{Chapter}*{Introduction}
\lipsum[3]
\end{Chapter}

\lipsum

\begin{Chapter}{Title}
\label{x}
\lipsum[2]
\end{Chapter}

This is chapter~\ref{x}.

\lipsum

\end{document}

enter image description here

2
  • I don't think that minipage works here, because I don't want to modify the chapter header. Apr 7, 2014 at 12:55
  • 2
    @LionelDarondeau Use titlesec for typesetting the chapter title in a minipage.
    – egreg
    Apr 7, 2014 at 14:05
0

You may use the package textpos like this:

\documentclass[oneside]{book}
\usepackage{lipsum}
\usepackage{layout}
\usepackage[absolute]{textpos}
\setlength{\TPHorizModule}{1pt}
\setlength{\TPVertModule}{1pt}
\textblockorigin{0pt}{0pt} % start everything near the top-left corner
\setlength{\parindent}{0pt}
\begin{document}
\layout
\newpage
\chapter*{Bla}
This is some text.
% left margin: one inch (72pt) + \hoffset (0pt) + \oddsidemargin (62pt) = 134
% halfpos: \paperheight (794pt) / 2 = 397
% width: \textwidht (345pt)

\begin{textblock}{345}(134,397) % coordinates are computed with layout package
  \lipsum[1]
\end{textblock}
\end{document}

to produce this: absolute posistioned textbox

If you need another position, you may play with the packages layout package, giving you the actual lengths.

HTH

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .