有没有一种优雅的方式垂直对齐段落边缘恰好到长度的一半其中?我知道使用 手动移动垂直位置的命令\marginnote{text}[voffset]
,但是当你有许多段落时这似乎有点累人。
梅威瑟:(带手动偏移)
\documentclass{scrreprt}
\usepackage{blindtext}
\usepackage{marginnote} %Margin note
\renewcommand*{\marginfont}{\sffamily\footnotesize} %Format of margin
\begin{document}
\marginnote{Lorem ipsum}[2.0cm]
\blindtext
\end{document}
提前致谢!
答案1
您可以尝试这样的操作,保存段落并测量其大小并输出恢复参数的文本。
\documentclass{scrreprt}
\usepackage{lipsum,blindtext} % Dummy text
\usepackage{marginnote} % Margin note
\renewcommand*{\marginfont}{\sffamily\footnotesize} % Format of margin
\newsavebox\mytempbox
\newlength{\currparindent}
\newcommand{\parwithmarginnote}[2]{\setlength{\currparindent}{\parindent}%
\sbox{\mytempbox}{%
\parbox[t]{\textwidth}{\setlength{\parindent}{\currparindent}
#2\par
\xdef\myprevdepth{\the\prevdepth}%
}%
}%
\marginnote{#1}[.5\dp\mytempbox]\par\noindent
\usebox{\mytempbox}\par
\prevdepth\myprevdepth}
\begin{document}
\lipsum[1]
\parwithmarginnote{Lorem ipsum}{\blindtext}
\lipsum[2]
\end{document}
答案2
所要求的功能需要有自己的软件包,事实上,这类功能需要比 LaTeX 为其用户提供的(LaTeX 只是 TeX 上的一层薄薄的层)更结构化的文档布局。如今,LuaTeX 可能提供了段落构建所需的钩子。
不管怎样,我们采用穷人的方法(这种方法甚至不考虑marginnote
包的实现方式)。当然,它有一些相当严重的局限性:其中一个是段落跨两页的情况……
这\myparnote
必须在源文件的段落末尾使用。
作为包的marginnote
使用\pdfsavepos
等等...至少需要 2 次编译。
\documentclass{article}
\usepackage{marginnote}
\usepackage{ragged2e}
\newcommand\myparnote[1]{%
\par
\xdef\zzz{\the\prevgraf}%
\marginnote{\smash{\parbox{\marginparwidth}{\RaggedRight#1}}}%
[-0.5\dimexpr\numexpr1+\zzz\relax\baselineskip\relax]%
}
\begin{document}
The command
\verb|\vadjust(filler){vertical mode material}|
is only allowed in horizontal and math modes (but it is not a (horizontal
command). Vertical mode material specified by \verb|\vadjust| is moved from the
horizontal list in which the command is given to the surrounding vertical
list, directly after the box in which it occurred.
\myparnote{Hello}
Any vertical material in a \verb|\vadjust| item is processed in internal
vertical mode, even though it will wind up on the main vertical list. For
instance, the \verb|\ifinner| test is true in a \verb|\vadjust|, and at the
start of the vertical material \verb|\prevdepth|=-1000pt.
\myparnote{I am here!}
The command
\verb|\vadjust(filler){vertical mode material}|
is only allowed in horizontal and math modes (but it is not a (horizontal
command). Vertical mode material specified by \verb|\vadjust| is moved from the
horizontal list in which the command is given to the surrounding vertical
list, directly after the box in which it occurred.
Any vertical material in a \verb|\vadjust| item is processed in internal
vertical mode, even though it will wind up on the main vertical list. For
instance, the \verb|\ifinner| test is true in a \verb|\vadjust|, and at the
start of the vertical material \verb|\prevdepth|=-1000pt.
\myparnote{Hi again,
it's me, and look how nice vertically centered I am.}
\end{document}
正如上面所示,OP 留下了一些关于“垂直对齐”的确切含义的关键问题,所以我们进行了猜测。