我想解决以下问题。
我想在文本中包含一些多行内容(在一个框、小页面或其他任何内容内),以便文本从左侧与顶行(框内内容)对齐,从右侧与底行对齐。
如有任何关于如何做到这一点的建议,我将不胜感激。
答案1
我不确定这是否是你想要的。 a 的第一行基线minipage
要与前面的文本对齐,但 的最后一行minipage
要与后面的文本对齐。
这是使用包 实现的tikzpagenodes
,包中有一个名为 的内置节点current page text area
。因此,在前面的文本之后,我们path
从当前行的末尾到左侧文本区域构造一个 (未绘制)。
然后,新段落以该路径开始,以正确缩进minipage
,并可以[b]
选择将其最后一行与后面的文本对齐。minipage
向上移动以与上一行文本对齐。
这一切都包装在一个带有两个参数的宏中:
\tbminipage{<width>}{<content>}
您必须编译两次。
\documentclass{article}
\usepackage{tikzpagenodes}
\newcommand{\tbminipage}[2]{\tikz[remember picture,overlay]
{\coordinate(a)at(0,0);\path (a) to (a-|current page text area.west);}
\par\vspace{-.66\baselineskip}\noindent\tikz{\path (a) to (a-|current page text area.west);}%
\begin{minipage}[b]{#1}#2\end{minipage}}
\begin{document}
This is the text that comes before. This is the text that comes before.
This is the text that comes before. This is the text that comes before.
This is the text that comes before. This is the text that comes before.
This is the text that comes before.
\tbminipage{2.5in}{This is the text in the middle. This is the text in the middle.
This is the text in the middle. This is the text in the middle.
This is the text in the middle. This is the text in the middle.
This is the text in the middle. This is the text in the middle.
This is the text in the middle.}
This is the text that comes after. This is the text that comes after.
This is the text that comes after. This is the text that comes after.
This is the text that comes after. This is the text that comes after.
\end{document}
答案2
你的意思是像这样吗?
This is a
part of the
surrounding +---------+
text. |This is |
|the boxed|
|content. | Here the surrounding
+---------+ text continues.
如果是,可以通过以下方式实现:
\splittopskip=\ht\strutbox
\setbox0=\vbox{\hsize=6em\leftskip=2pt\rightskip=\leftskip
\penalty0 %first \vsplit here
\noindent\strut This is the boxed con\-tent.\strut\par}
\hbox to\hsize{%
\vbox{\hsize=6em
This is a part of the surrounding text.\par}%
\kern6pt
\setbox1=\vsplit0 to0pt %insert \splittopskip at the top of \box0
\hbox{\vrule\vbox{\hrule\kern-.4pt\vsplit0 to\ht\strutbox}\vrule}
\hfil
}\nointerlineskip
\hbox to\hsize{%
\kern6em
\kern6pt
\dimen1=\dp0 \setbox1=\vbox{\box0 \kern-.4pt\hrule}\dp1=\dimen1
\multiply\dimen1 by-1\advance\dimen1 by\ht1 \ht1=\dimen1
\hbox{\vrule\box1 \vrule}
\kern6pt
\vtop{\hsize=6em
\noindent Here the surrounding text continues.\par}%
\hfil
}
但这个解决方案(重用了有两个带对齐的右括号) 假定周围的文本不占用整个页面宽度,并且也没有分页。