如何修改侧注中的字体?

如何修改侧注中的字体?

我想更改旁注的字体显示方式。为此,我进行了修改\marginfont,并获得了所需的结果。具体来说,这在\marginnote{}和 下 效果很好\sidenote{},但有一个警告。只有当我给出一个具体值时,它才适用于旁注offset。也就是说,只有当我给出 时,文本格式才会起作用\sidenote[][0cm]{}

如果我没有在给定的旁注中提供偏移量,它将恢复为正常字体,并开始新的编号。我想知道为什么会发生这种情况,以及如何在没有偏移的情况下设置旁注的格式。

MWE 附于下方

\documentclass{article}

\usepackage{sidenotes}

\renewcommand*{\marginfont}{\small\sffamily}

\begin{document}


Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed. \sidenote[1][0pt]{This is a sidenote, which is set with offset of 0pt. And the formatting is correct.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed. \sidenote{This is a sidenote with no offset, and the formatting doesn't work here, neither does the numbering.}


Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\marginnote{This is a margin note with correct formatting.} 

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\sidenote{This is a sidenote with no offset, and the formatting doesn't work here, and this has its own numbering.}

Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.

 Furthermore, they were emboldened to play a game of  hide and seek with the imperialists whom they harassed incessantly by plundering their convoys and by interrupting their lines of communication. Status quo came from or how it should be changed.\sidenote[][1cm]{This is a side note with offset again and formatting works.}

\end{document}

旁注

答案1

这可能是sidenotes软件包 v1.00 的一个错误。

  • 如果的第二个可选参数\sidenote未给出或为空,则\sidenote扩展为\marginpar,它由 latex2e 格式定义。
  • 否则,\sidenote扩展为\marginnote,由包定义marginnote
  • \marginfont被 使用\marginnote,但不是。因此或 的\marginpar字体不受 的影响。\sidenote{...}\sidenote[...][]{...}\marginfont

以下几行\sidenote统一使用\marginnote,从而修复了该问题:

\makeatletter
\ExplSyntaxOn
\RenewDocumentCommand \@sidenotes@placemarginal { m m }
{
  \IfNoValueOrEmptyTF{#1}
    % substitue \marginnote from marginnote pkg for \marginpar 
    % from latex2e format
    {\marginnote{#2}}
    {\marginnote{#2}[#1]}
}
\ExplSyntaxOff
\makeatother

答案2

免责声明:我是该软件包的作者sidenotes,当然有偏见;)

我之前也遇到过同样的问题,也问过类似的问题这里。但是,答案故意没有包含在sidenotes包中,因为它操纵了一个LaTeX可能产生副作用的宏。始终使用\marginnote仅适用于稀少的边距。否则,它们将开始重叠。调用marginfix包也总是一个好主意。

但是,示例caesar.cls包含在sidenotes软件包中。如果您使用,\documentclass{caesar_book}您可以查看它是否解决了您的问题(在本例中确实如此)。之后,您可以决定是否要复制代码片段。

顺便说一句(双关语),你可能想考虑一下xparse解决方案。从今天的角度来看,我更喜欢它,并且可能会在下一版中改变它caesar.cls

从其他答案复制相关代码(归功于埃格尔):

\usepackage{xparse}
\let\oldmarginpar\marginpar
\RenewDocumentCommand{\marginpar}{om}{%
  \IfNoValueTF{#1}
    {\oldmarginpar{\mymparsetup #2}}
    {\oldmarginpar[\mymparsetup #1]{\mymparsetup #2}}}

\newcommand{\mymparsetup}{\itshape}

相关内容