我们可以使用\makebox[0pt]{text}
来创建一个逻辑上宽度为 0pt 的框(好像周围什么都不存在,而实际上我们可以在其中放置任何东西)。我的问题是---什么是对应的命令,可以使一个框的高度在逻辑上相对于其相邻的框显示为 0pt。使用这样的框,在 之后\newline
,下一行将出现在同一页上上一行的垂直位置。
答案1
回答你写的问题:你可以通过将盒子的高度存储到盒子寄存器中并将高度设置为 0pt 来删除盒子的高度,然后使用该盒子。你可能还想将深度设置为 0pt。轻松做到这一点的方法是使用包adjustbox
:\adjustbox{set height=0pt, set depth=0pt}{Some Text}
或者,如果没有包,\raisebox{0pt}[0pt][0pt]{Some Text}
。
请注意,这只会使框没有正式的垂直尺寸,但它仍放置在构成行的水平列表中。在段落内,所有字符和其他材料(如图像)都由 TeX 建模为具有高度、深度和宽度的框,并放置在构成行的列表中,直到足以构成完整的行。所有这些框都位于一行上,基线,该线上方的所有内容构成高度,该线下方的所有内容构成深度。TeX 通常将量放置\baselineskip
在两个连续线的基线之间。
因此,如果要在最后一行上套印下一行,请删除第一行内容的官方高度和深度没有效果,因为仍然添加了 baselineskip。为了实现这一点,您需要再次撤消 baselineskip,以便第二行从与第一行相同的垂直位置开始。\vspace{-\baselineskip}
在大多数情况下,可以使用两条线之间来完成此操作。请注意,如果第一行包含深度非常大的材料,那么两条线之间的距离将超过\baselineskip
!此外,如果在那里有一个段落分隔符,那么 LaTeX 可能会根据全局设置在最后一段的最后一行和下一段落的第一行之间添加更多空间(例如使用包;用于获取德文段落样式)。此外,如果处于活动状态,LaTeX 会尝试通过增加段落间间距将parskip
段落分散到整个页面上。在这种情况下,您可能需要使用而不是。\flushbottom
\\
\par
答案2
\documentclass{article}
\usepackage{color}
\newbox\mybox
\begin{document}
Some text pppp
Some text pppp
\setbox\mybox\vbox{% some arbitrary contents
\begingroup\color{red}
% some paragraphs
\hspace*{5cm}aaa, bbb, ccc\par
\hspace*{5cm}ppp, qqq, rrr\par
% some vertical space
\vspace*{1cm}
% some more paragraphs
\hspace*{5cm}uuu, vvv, www\par
\hspace*{5cm}xxx, yyy, zzz\par
\endgroup}
% set the box to occupy zero space
\ht\mybox0pt
\dp\mybox0pt
% insert it in a way keeping \prevdepth
\setbox\mybox\vbox{\box\mybox}
\unvbox\mybox
Some text pppp
Some text pppp
\end{document}
限定建议:(如果插入的内容也是段落,则可能需要一些对齐)
\documentclass{article}
\usepackage{color}
\newbox\mybox
\newdimen\myprevdepth
\begin{document}
Some text pppp
Some text pppp
\myprevdepth\prevdepth
\setbox\mybox\vbox{% some arbitrary contents
\prevdepth\myprevdepth
\begingroup\color{red}
% some paragraphs
\hspace*{5cm}aaa, bbb, ccc\par
\hspace*{5cm}ppp, qqq, rrr\par
% some vertical space
\vspace{2\baselineskip}
% some more paragraphs
\hspace*{5cm}uuu, vvv, www\par
\hspace*{5cm}xxx, yyy, zzz\dotfill\par
\endgroup}
% set the box to occupy zero space
\ht\mybox0pt
\dp\mybox0pt
% insert it in a way keeping \prevdepth
\setbox\mybox\vbox{\box\mybox}
\unvbox\mybox
Some text pppp\dotfill
Some text pppp\dotfill
And more paragraphs...
\mbox{}\cleaders \hbox to .44em{\hss .\hss }\hskip5cm This is regular
text\dotfill\newline which continues here\dotfill
\end{document}
我正在添加一个可以避免这个\unvbox
技巧并且不需要处理的变体\prevdepth
。
\documentclass{article}
\usepackage{color}
\newbox\mybox
\begin{document}\parskip2pt
Some text pppp (parskip is 2pt in this example)
Some text\rule{1cm}{1pt} pppp
\setbox\mybox\vtop{% some arbitrary contents
\hrule height 0pt
\vbox{}\vskip-\baselineskip
\begingroup\color{red}
% some paragraphs
\hspace*{5cm}aaa, bbb, ccc\par
\hspace*{5cm}ppp, qqq, rrr\par
% some vertical space
\vspace{\dimexpr2\baselineskip+\parskip\relax}
% some more paragraphs
\hspace*{5cm}uuu, vvv, www\par
\hspace*{5cm}xxx, yyy, zzz\dotfill\par
\endgroup}
% set the box to occupy zero space
\ht\mybox0pt
\dp\mybox0pt
\box\mybox % this will get the correct baseline
\vskip-\baselineskip
Some text pppp\smash{\rule{1pt}{\dimexpr\baselineskip+\parskip}}\dotfill
Some text pppp\dotfill
And more paragraphs...
\mbox{}\cleaders \hbox to .44em{\hss .\hss }\hskip5cm This is regular
text\dotfill\newline which continues here\dotfill
\end{document}
答案3
这本质上只是一条评论,但 600 个字符不足以容纳它:这是您想要实现的吗?
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\newenvironment*{overlap}{%
\par
\null
\setlength\baselineskip{0pt}%
\setlength\lineskip{0pt}%
\setlength\lineskiplimit{-\maxdimen}%
\setlength\parskip{0pt}%
}{\par}
\begin{document}
This is too long for a comment: is it this what you expected?
\begin{overlap}
\noindent A few\\
\makebox[1cm]{}overlapping\\
\makebox[3cm]{}lines.
..................................And another paragraph.
\end{overlap}
More text.
\end{document}
我忘了:这是输出。
OP问对于上面的版本,当字体大小改变时不会崩溃;它在这里:
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
\usepackage{color}
\newenvironment*{overlap}{%
\par
\null
\linespread{0}\selectfont
\setlength\lineskip{0pt}%
\setlength\lineskiplimit{-\maxdimen}%
\setlength\parskip{0pt}%
}{\par}
\begin{document}
This is too long for a comment: is it this what you expected?
\begin{overlap}
\noindent A few\\
\makebox[1cm]{}overlapping\\
\makebox[3cm]{}lines.
..................................And another paragraph.
\end{overlap}
More text.
Now it works also if you change the font size:
\begin{overlap}
\noindent A few\\
\Large \makebox[1cm]{}overlapping\\
\makebox[3cm]{}lines.
\color{cyan}\Huge ..................................And another paragraph.
\end{overlap}
Still more text.
\end{document}
相应的输出:
我(还)不会提供任何解释,因为还不清楚这是否是 OP 想要实现的。