将 marginpar 的“底部”与段落的“最后一行”对齐

将 marginpar 的“底部”与段落的“最后一行”对齐

如果我排版以下内容,(显然)顶部marginpar 与段落最后一行对齐,看起来很丑。

\documentclass{article}
\begin{document}
Some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text.\marginpar{Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\end{document}

有没有办法对齐底部与段落最后一行相等的边距?

答案1

是的。请注意,它突出于文本区域的顶部。

\documentclass{article}
\begin{document}
Some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text some text.
\marginpar{\raisebox{\height}[0pt]{\parbox{\marginparwidth}{\sloppy Lorem ipsum dolor sit amet, consectetur adipiscing elit.}}}
\end{document}

答案2

基于 John Kormylo 之前的回答,我尝试解决如果上一段只延伸到下一页一点点,框就会被抬得太高的问题。

\documentclass{article}
\usepackage{kantlipsum}
\usepackage{etoolbox}

\newcommand{\marginparbottom}[1]{
  \marginpar{%
    \raisebox{
      \ifdimcomp{\height}{>}{\pagetotal}{%
          \dimexpr\pagetotal-5.95pt\relax
        }{%
          \dimexpr\height\relax%
        }%
      }{%
        \parbox{\marginparwidth}{\sloppy #1}%
      }
    }
  }

\begin{document}
\section{One}
\kant[1-3]
\section{Two}
\kant[1]
\marginparbottom{ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit.}
\end{document}

这在某种程度上是可行的,但出于某种原因,在 if-true-clause 中手动计算基线偏移量没有任何效果。如果边距段落中的第一个水平框不高于主体中的第一个水平框,那就太好了。

相关内容