我在使用文档类时插入边注时遇到问题ltxdoc
。我看到默认布局如下:
据我所知,边注之所以这样设置,是因为该\DescribeMacro
命令将宏名称作为边注。我想利用正确的边距来插入我自己的边注。我尝试使用
\reversemarginpar\marginpar{Some text to be placed in the right margin}
但这并没有达到我想要的效果。我也尝试过使用该marginnote
包,但没有成功...
\marginnote{Still not on the right}
我怎样才能将文本放在右边距?以下是 MWE:
\documentclass{ltxdoc}
\usepackage{lipsum}
\usepackage{marginnote}
\newcommand{\rmarginpar}[1]{\reversemarginpar\marginpar{#1}}
\begin{document}
\lipsum[1-2]
\marginpar{This marginal note is on the left. This behavior is expected based on
the page layout.}
\rmarginpar{This marginal note is also on the left, but I want it to appear on the
right of the text.
Even worse, this marginal note overlaps the first note.}
\marginnote[This is on the left, as expected]{}[1in]
\marginnote{This should be on the right of the text.}[2in]
\end{document}
更新 2016/03/08
我也尝试过使用marginfix
和mparhack
包。这些也没有解决我的问题。唯一的改进是加载marginfix
包使得\marginpar
不再重叠,但这不是我想要修复的问题。
答案1
也许类似的东西使用tabto
包。的顶部\rmarginpar
应该在调用线上。我提供了一个可选参数来为 提供垂直移位\rmarginpar
,以帮助用户避免重叠。
在下面的 MWE 中,我使用红色表示\rmarginpar
,只是为了更容易看到添加的内容。
\documentclass{ltxdoc}
\usepackage{lipsum}
\usepackage{marginnote}
\usepackage{tabto,xcolor}
\newcommand\rmarginpar[2][0pt]{\leavevmode%
\tabto*{\dimexpr\linewidth+10pt}\smash{\raisebox{%
\dimexpr.6\ht\strutbox+#1}{\parbox[t]{2.5cm}{%
\scriptsize\color{red}\raggedright#2}}}\tabto*{\TabPrevPos}%
}
\begin{document}
\lipsum[1]
\marginpar{This marginal note is on the left. This behavior is expected based on
the page layout.}
\rmarginpar[20pt]{This marginal note that is made
to appear on the right of the text.
I have shifted it up by 20 pt.}
\marginnote[This is on the left, as expected]{}[1in]
\marginnote{This should be on the right of the text.}[2in]
\lipsum[2]
And now here is the third paragraph.
\rmarginpar{Another right marginpar, this one lowered a line.}
\end{document}
答案2
好的,我找到了一个使用该tikzpagenodes
包的解决方案。我定义了一个新命令\rmarginpar
,将tikz
节点放置在我想要的位置。
\documentclass{ltxdoc}
\usepackage{lipsum}
\usepackage{tikzpagenodes}
\newcommand{\rmarginpar}[1]{
\tikz[remember picture, overlay] {%
\node[anchor = west, xshift = \textwidth, text width = {\oddsidemargin - 2ex}]
{#1};
}%
}
\begin{document}
\lipsum[1]
\marginpar{This marginal note is on the left. This behavior is expected based on
the page layout.}
\lipsum[2]
\rmarginpar{Hooray! I got this on the right of the text!}
\end{document}
我对这个方法还存在一些问题:
- 感觉很“老套”……这与正常的边注无关。我只是在计算页面上放置一些文本的位置。
- 文本在插入处垂直居中。我更希望文本的垂直放置表现得像正常的
\marginpar
。 - 多个注释相互重叠,现在该
marginfix
软件包无法修复该问题。
也许有人有更好的主意?
更新日期:2016/03/11
上述解决方案还有另一个主要问题。具体来说,使用\rmarginpar
上述定义输入的注释必须在换行符或段落符之后输入,否则xshift
会将注释推离页面。例如:
\documentclass{ltxdoc}
\usepackage{lipsum}
\usepackage{tikzpagenodes}
\newcommand{\rmarginpar}[1]{%
\tikz[remember picture, overlay] {%
\node[anchor = west, xshift = \textwidth, text width = {\oddsidemargin - 2ex}]
{#1};
}%
}
\begin{document}
This is a sentence. Here is another one, but this one is a bit longer. Short
sentence. A medium length sentence.
\rmarginpar{I need a new line or new paragraph for this note to appear.}
This is a sentence. Here is another one,
but this one is a bit longer. Short sentence. A medium length sentence. This is
a sentence. Here is another one, but this one is a bit longer. Short sentence.
A medium length sentence. This is a sentence. Here is another one, but this one
is a bit longer. Short sentence.
\rmarginpar{This margin note does not appear since the \texttt{xshift} pushes
it off the page.}
A medium length sentence. This is a sentence. Here is another one, but this
one is a bit longer. Short sentence. A medium length sentence. This is a
sentence. Here is another one, but this one is a bit longer. Short sentence. A
medium length sentence. This is a sentence. Here is another one, but this one
is a bit longer. Short sentence. A medium length sentence.
\end{document}
输出: