LaTeX 旁注 边注 Marigin Note
原 文:Margin notes
译 者:Xovee
翻译时间:2022年10月31日
文章目录
介绍
本文介绍如何在LaTeX中插入旁注(Margin note)。旁注是脚注的另外一种流行的形式。
\marginpar
命令
你不需要引入任何外部的包就可以使用LaTeX内部命令\marginpar
来添加旁注。语法命令为:
\marginpar[left text]{right text}
如果旁注显示在正文的左侧,则该命令会显示left text
参数中的文字;同理,旁注出现在正文右侧,则显示right text
中的文字。一般来说,旁注出现在页面的外边。具体的显示效果取决于你所使用的twoside
包的选项。例如:
book
类型的文档默认是两边的(two-sided)report
类型的文档和article
类型的文档时单边的(single-sided)。如果你想对这两类型的文档使用双边选项,你需要使用下面的命令:\documentclass[twoside]{report}
\documentclass[twoside]{article}
对于单边类型的文档(除了从右向左书写的文字例如阿拉伯语),页面的外部一般指文字的右侧。对于双边类型的文档,页面的外部对于左手类型的页面是在左边(left-hand pages),对于右手类型的页面是在右边(right-hand pages)。
改变旁注的位置(左或右)
一般使用\reversemarginpar
命令。对于双边类型的文档,该命令不起作用。你可以使用\normalmarginpar
来恢复默认的旁注位置。
自定义旁注样式
你可以使用下面的命令来自定义旁注的样式:
\marginparwidth
:旁注的宽度\marginparsep
:旁注和正文的间距\marginparpush
:多个旁注之间的最小(垂直)距离
自定义旁注样式:左对齐和右对齐
一般来说,旁注的宽度不是很长,因此,LaTeX需要考虑换行等问题。我们可以使用类似于左对齐、右对齐、两端对齐(Justified)等来达到理想的格式效果。
左对齐命令:\raggedright
(命令的单词的意思是,右边是“破烂的”,不对齐的)
右对齐命令:\raggedleft
例子:
\documentclass[twoside]{article} % Note: uses twoside option
\usepackage[a4paper, marginparwidth=75pt, total={10cm, 10cm}]{geometry} % To create a small page
\usepackage{hyperref} % To use the \url command (in the footnote)
\usepackage{marginnote}
\begin{document}
\section{Lorem Ipsum}
\footnote{Source text: Wikipedia (\url{https://en.wikipedia.org/wiki/Lorem_ipsum})}But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose. To do so, I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. \marginpar[Note 1: text for left-hand side text]{Note 1: text for right-hand side of pages, it is set justified.} No one rejects, dislikes or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. \marginpar[Note 2: text for left-hand side text]{\raggedright Note 2: text for right-hand side of pages, it is not justified, but uses \texttt{\string\raggedright}.} To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? [33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. \marginpar[\raggedleft Note 3: text for left-hand side of pages, it is not justified, but uses \texttt{\string\raggedleft}]{Note 3: text for left-hand side of pages}But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
\end{document}
mparhack
包:修复错误的边距Margin
LaTeX内部将旁注看作是浮动元素,类似于图片和表格。它们有时候会出现在错误的地方。如果你遇到了这样的问题,可以使用mparhack来修复这个问题。
添加旁注的另外一个工具:marginnote
包
marginnote包提供了非常多强大的添加旁注的功能。它使用非浮动的方法来创建旁注。尽管这个包可以解决一些问题,但也可能引入新的问题。
例子
下面的例子解释了如何使用marginnote
包中的\parginnote
命令。
\documentclass{article}
\usepackage[a5paper, total={3in, 6in}]{geometry} % to create a small page
\usepackage{hyperref} % To use the \url command (in the footnote)
\usepackage{marginnote}
\begin{document}
\section{Lorem Ipsum}
\footnote{Source text: Wikipedia (\url{https://en.wikipedia.org/wiki/Lorem_ipsum})}But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose. To do so, I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. \marginnote{This is a margin note shifted 2cm, \textit{down} the page, relative to the line in which it is typeset.}[2cm] No one rejects, dislikes or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but occasionally circumstances occur in which toil and pain can procure him some great pleasure. \reversemarginpar\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm] To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? [33] On the other hand, we denounce with righteous indignation and dislike men who are so beguiled and demoralized by the charms of pleasure of the moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound to ensue; and equal blame belongs to those who fail in their duty through weakness of will, which is the same as saying through shrinking from toil and pain. These cases are perfectly simple and easy to distinguish. In a free hour, when our power of choice is untrammeled and when nothing prevents our being able to do what we like best, every pleasure is to be welcomed and every pain avoided. But in certain circumstances and owing to the claims of duty or the obligations of business it will frequently occur that pleasures have to be repudiated and annoyances accepted. The wise man therefore always holds in these matters to this principle of selection: he rejects pleasures to secure other greater pleasures, or else he endures pains to avoid worse pains.
\end{document}
上面的例子也导入了geometry
包来创建一个较小的页面,以及导入hyperref
包来使用\url
命令给出文字的来源链接(见脚注)。
我们首先导入marginnote
包:
\usepackage{marginnote}
然后使用了下面两个命令:
\marginnote{This is a margin note shifted 2cm, \textit{down} the page, relative to the line in which it is typeset.}[2cm]
\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm]
我们在中括号里使用了一个额外的参数,用来改变旁注出现的位置(例如往上两厘米,或者往下两厘米)。
在第二个命令之前,我们使用了\reversemarginpar
命令,来让该旁注出现在单边文档的左侧。
\reversemarginpar\marginnote{This is another margin note but shifted 2cm \textit{up} the page, relative to the line in which it is typeset. It is also in the left-hand margin.}[-2cm]