当页面的前半部分已经写了一些内容时,如何从页面中间开始一个段落?
例如
\chapter*{Blabla}
\lipsum[1-2]
\gotohalf
\lipsum[3] <- the first line of this paragraph should start from the half of the text height (vertically)
编辑我不认为 minipage 是一个解决方案,因为我不想修改章节标题的外观。
答案1
\pagegoal
,\pagetotal
\pagegoal
是一个内部寄存器,包含需要填充的高度,\pagestotal
是已经填充的数量。
例子:
\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}
然而,也存在严重的局限性:
\pagegoal
LaTeX 的输出程序是异步的, /的当前值\pagetotal
可能不太准确。在章节的起始页,它可能会起作用。- 底部的东西(例如浮动物体)不被考虑,因此中间向上移动。
包裹zref-savepos
\pdfsavepos
可用于记录当前位置,许多 TeX 编译器(pdfTeX、LuaTeX、XeTeX;PDF 和 DVI 两种模式)均支持该功能。页面位置可存储在文件中.aux
,并在下一次 LaTeX 运行中使用。因此至少需要两次 LaTeX 运行。
软件包zref-savepos
添加了一个用户界面\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}
答案2
将框的高度设置为文本高度的一半;必须添加一些小的调整:
\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}
如果您想使用通常的标题(或使用titlesec
其他包定制的标题),只需定义一个新环境:
\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}
答案3
您可以使用该包文本位置像这样:
\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}
生成如下内容:
如果您需要其他位置,您可以使用包布局包,它会为您提供实际的长度。
高血压