我必须排版一本包含大量附加材料(评论、注释、参考文献、补充说明等)的书,我希望这些附加材料与主要材料一起出现。
一开始我想用tufte-latex
班级,为页边注留出了相当大的空间。不幸的是,我必须使用b5
不允许太大页边注的纸张尺寸。另外,我不喜欢在没有页边注时页面上会有很多“空白”空间。
我的想法是创建一种“侧注”,它将与发布侧注的正文共享相同的空间,这样:
- 每个段落及其所有旁注将采用类似双栏布局的排版;
- 旁注会出现在右栏;正文会出现在左栏;
- 附注应使用较小的字体排版;
- 每个旁注都将在彩色背景的单个“框”中排版,并且可以为每个旁注单独指定颜色;
- 应该根据正文和边文的比例计算每个段落两列的宽度分布,以获得适当的平衡,这意味着:
- 若没有旁注,则段落应使用全文宽度排版;
- 如果有旁注,则包含旁注的右列的宽度应介于最小值(例如
0.3\textwidth
)和最大值(例如0.5\textwidth
)之间; - 右列的高度不应超过左列的高度;
- 任何旁注都不应跨页;
- 如果前面的标准不能满足,那么边注应该出现在正文之后,使用全文宽度(可能会跨页)
我知道我的要求太多了,也许这应该是一个包裹,但我认为这些标准可以让我的书取得好成绩。
不幸的是,我没有足够的“TeXperience”来完成这项任务,因此非常感谢任何帮助。
编辑:这是我脑海中想到的一个例子。它很可能包含很多数学知识。
答案1
编辑:我已更新下面的解决方案以使用 wrapfig 环境,这至少简化了部分代码。这解决了我之前遇到的所有间距问题。我还更改了命令的定义,使其仅要求将其放在每个段落之前,并添加了将长注释放在新行上的功能。唯一剩下的问题是,该解决方案仍然无法很好地处理分页符,而且在每个段落之前放置相同的命令非常麻烦,即使它比我之前的解决方案的语法更简单。
我现在有了一个新的解决方案(在 David Carlise 的帮助下),我认为它比我上次的尝试更接近您的预期。但它仍然存在一些问题:
- 段落之间有时会出现一些不需要的空格
- 注释从不分行
- 段落内不允许使用侧边栏
现在的结果如下图所示:
还有源代码.. :)
\documentclass[10pt]{article}
% Packages
\usepackage[newcommands]{ragged2e}
\usepackage{newfile}
\usepackage{color}
\usepackage{xparse}
\usepackage{graphics}
\usepackage[dvipsnames]{xcolor}
\usepackage{hyperref}
\usepackage{wrapfig}
\usepackage{ifthen}
% Settings
\colorlet{Pbardefault}{yellow!70} % Default color for the colored bar left to the notes
\colorlet{Plightdefault}{yellow!10}% Default color for background of the note
\def\Pmin{0.5} % ~minimal amount main text
\def\Pmax{0.95} % ~maximal amount main text / \Psf
\def\Psf{1.14} %
\newcounter{localsidenotecounter}
\newlength{\currentparskip}
\setlength{\currentparskip}{\parskip}
% The formatting of the note
\newdimen\Pparsep
\Pparsep=0.2em
\newdimen\Pcolorwidth
\Pcolorwidth=2mm
% The paragraph command
\makeatletter
\def\sidenotepi#1\par%
{
%
\immediate\openout\tempfile=sidenotes.tex %
%
\twopara%
{
#1 \immediate\closeout\tempfile
}
{\input{sidenotes.tex}}
}
\makeatother
% A command for finding the optimal text widths
\makeatletter
\long\def\twopara#1#2{%
\newdimen\columnsep
\columnsep=\dimexpr \Pparsep + \Pcolorwidth
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
\edef\TY@ckpt{\cl@@ckpt}%
\@tempdima\dimexpr\textwidth-\columnsep\relax
{\hbadness\@M\raggedright\hsize.5\@tempdima \@tempdima\hsize
\setbox\z@\vbox{{#1\endgraf}}%
\setbox\tw@\vbox{{#2\endgraf}}%
\Gscale@div\tmp{\ht\z@}{\dimexpr\ht\z@+\ht\tw@\relax}%
\global\let\xtmp\tmp}%
\dimen@ \xtmp\@tempdima
\ifdim\dimen@<\Pmin\@tempdima \dimen@\Pmin\@tempdima\fi
\ifdim\dimen@>\Pmax\@tempdima \dimen@\Pmax\@tempdima\fi
\dimen@ii\dimexpr\@tempdima-\dimen@\relax
\TY@ckpt
\ifdim\dimen@ii<20pt
#1
\else
\ifdim \Psf\dimen@ii>\dimexpr\textwidth-\Pmin\textwidth
#1
\let\Pnotebox\Pnotebox@
\dimen@ii = \dimexpr \textwidth-4mm
\setlength{\intextsep}{2pt}%
\begin{figure}[h]
#2
\end{figure}
\else
\let\Pnotebox\Pnotebox@
\dimen@ii\dimexpr\Psf\dimen@ii
\setlength{\intextsep}{0pt}%
\begin{wrapfigure}{o}[-4mm]{\dimen@ii}
#2
\end{wrapfigure}
#1
\fi
\fi
\let\Pnotebox\Pnotebox@@
}
\makeatother
% The unformatted note text
\makeatletter
\long\def\Pnotebox@@#1#2#3{ %barcolor, backcolor, text
#3}
\makeatother
\makeatletter
\long\def\Pnotebox#1#2#3{ %barcolor, backcolor, text
#3}
\makeatother
% The formatting of the notes
\makeatletter
\newdimen\Pnoteheight
\long\def\Pnotebox@#1#2#3{ %barcolor, backcolor, text
\settoheight{\Pnoteheight}{\parbox{\dimen@ii}{#3}}%
\begin{minipage}{\dimexpr\dimen@ii+\Pcolorwidth}
\textcolor{#1}{\rule[\dimexpr-\Pnoteheight+1mm]{\Pcolorwidth}{\dimexpr 2\Pnoteheight}}%
\colorbox{#2}{\parbox{\dimen@ii}{#3}}
\end{minipage}%
}
\makeatother
% Commands for making the sidenote
\newwrite\tempfile
\makeatletter
\DeclareDocumentCommand \sidenote {m O{Pbardefault} O{Plightdefault}} {%
\stepcounter{localsidenotecounter}%
\hyperlink{sidenote\arabic{localsidenotecounter}}{${}^\textrm{\footnotesize\arabic{localsidenotecounter}}$}%
\immediate\write\tempfile%
{%
\noexpand\Pnotebox{#2}{#3}{%
\noexpand\footnotesize \noexpand{\noexpand\hypertarget{sidenote\arabic{localsidenotecounter}}{${}^{\arabic{localsidenotecounter}}$} \unexpanded{#1 }}%
}}}
\makeatother
\begin{document}
\sidenotepi
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and 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. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure} 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 because occasionally circumstances occur in which toil and pain can procure him some great pleasure
\sidenotepi
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and 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. 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 because occasionally circumstances occur in which toil and pain can procure him some great pleasure.
\sidenotepi
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and 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. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure} 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 because occasionally circumstances occur in which toil and pain can procure him some great pleasure.\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure.}[blue][blue!5]
\end{document}
答案2
我确实意识到这不是一个完整的解决方案,但它至少是一个部分解决方案。它没有做到以下几点:
- 未使用任何颜色
- 没有以全文宽度排版的注释
- 水平空间被笔记占据的面积没有限制
- 没有处理接近或跨分页符的注释(每个带有注释的段落都会自动从新页面开始,并且这个问题可能无法在表格环境中修复,就像我使用的一样,因为没有表格环境可以在单元格内自动分页)
此外,注释的编号有问题,我猜这是 tabulary 包内部运作的问题(似乎该命令被调用了两次),但希望比我更熟练的人可以发现错误.. :)
编辑:tabulary 包中有一个错误,已在下面的代码中修复。(在大卫·卡莱尔
编辑:我做了一个修复,使注释开头的数字与注释位置的数字相匹配,看起来像脚注中的相应数字。我还添加了更改注释颜色的可能性。
\documentclass[]{article}
\usepackage{tabulary} % used for automatic adjustment of column width
\usepackage[newcommands]{ragged2e} % ragged text and allow hyphenation
\usepackage{array} % for specifying the padding for the tabulary table
\tymin=0.1\textwidth % settings for the tabulary package
\tymax=10\textwidth
\renewcommand{\tabcolsep}{0cm}
\newcommand{\colspace}{1em}
\AtBeginDocument{\edef\normalparindent{\the\parindent}} % saved the parindent to allow it to be mimicked inside the tabulary environment
\usepackage{newfile} % for enabling writing to a file
\newwrite\tempfile
\makeatletter
% A long hack to fix a bug in the tabulary package
\def\endtabulary{%
\gdef\@halignto{}%
\def\@elt##1{\global\value{##1}\the\value{##1}\relax}%
\edef\TY@ckpt{\cl@@ckpt}%
\expandafter\TY@tab\the\toks@
\crcr\omit
{\xdef\TY@save@row{}%
\loop
\advance\TY@count\m@ne
\ifnum\TY@count>\z@
\xdef\TY@save@row{\TY@save@row&\omit}%
\repeat}\TY@save@row
\endarray\global\setbox1=\lastbox\setbox0=\vbox{\unvbox1
\unskip\global\setbox1=\lastbox}\egroup
\dimen@\TY@linewidth
\divide\dimen@\TY@count
\ifdim\dimen@<\tymin
\TY@warn{tymin too large (\the\tymin), resetting to \the\dimen@}%
\tymin\dimen@
\fi
\setbox\tw@=\hbox{\unhbox\@ne
\loop
\@tempdima=\lastskip
\ifdim\@tempdima>\z@
\global\advance\TY@linewidth-\@tempdima
\fi
\unskip
\setbox\tw@=\lastbox
\ifhbox\tw@
\ifdim\wd\tw@>\tymax
\wd\tw@\tymax
\fi
\TY@width\dimen@
\advance\dimen@\wd\tw@
\TY@width\xdef{\the\dimen@}%
\ifdim\dimen@<\tymin
\global\advance\TY@linewidth-\dimen@
\expandafter\xdef\csname TY@F\the\TY@count\endcsname
{\the\dimen@}%
\else
\expandafter\ifx\csname TY@F\the\TY@count\endcsname\z@
\global\advance\TY@linewidth-\dimen@
\expandafter\xdef\csname TY@F\the\TY@count\endcsname
{\the\dimen@}%
\else
\global\advance\TY@tablewidth\dimen@
\global\expandafter\let\csname TY@F\the\TY@count\endcsname
\maxdimen
\fi\fi
\advance\TY@count\m@ne
\repeat}%
\TY@checkmin
\TY@checkmin
\TY@checkmin
\TY@checkmin
\TY@count\z@
\let\TY@box\TY@box@v
\TY@ckpt
{\expandafter\TY@final\the\toks@\endTY@final}%
\count@\z@
\@tempswatrue
\@whilesw\if@tempswa\fi{%
\advance\count@\@ne
\expandafter\ifx\csname TY@SF\the\count@\endcsname\relax
\@tempswafalse
\else
\global\expandafter\let\csname TY@F\the\count@\expandafter\endcsname
\csname TY@SF\the\count@\endcsname
\global\expandafter\let\csname TY@\the\count@\expandafter\endcsname
\csname TY@S\the\count@\endcsname
\fi}%
\TY@linewidth\@ovxx
\TY@tablewidth\@ovyy
\ifnum0=`{\fi}}
\newcounter{localsidenotecounter} % defines a counter for the notes
\usepackage{color} % for coloring the notes
\newcommand{\sidenote}[2][black]
{%
\stepcounter{localsidenotecounter} % increases the counter by one
${}^\textrm{\footnotesize\arabic{localsidenotecounter}}$ % formats the small number to be put in the text to mark the existance of a note
\immediate\write\tempfile % saves the note with some of its formatting to a file
{
\noexpand\textcolor{#1}{${}^{\arabic{localsidenotecounter}}$ #2}
\noexpand\vspace{0.5em} % adds some space between the notes
}%
}
\newcommand{\sidenotepc}[1] % defines a command for paragraphs with notes
{ % sets some settings for the table
\noindent \begin{tabulary}{\textwidth}{>{\setlength\parindent{\normalparindent} \immediate\openout\tempfile=sidenotes.tex }J<{\immediate\closeout\tempfile}@{\hspace{\colspace}}>{
\footnotesize \input{sidenotes.tex}
}J}
#1 & \end{tabulary}
}
\makeatother
\begin{document}
\sidenotepc{
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and 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. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Test} 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 because occasionally circumstances occur in which toil and pain can procure him some great pleasure\sidenote[red]{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure}\sidenote{Blaha}.
}
\sidenotepc{
But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and 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. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure} 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 because occasionally circumstances occur in which toil and pain can procure him some great pleasure\sidenote{Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure}
}
\end{document}
答案3
现在,您可以大致了解一下可以使用wrapfig
和做什么tcolorbox
。我现在没有时间改进它,不过您可以尝试一下并阅读文档,以使其适应您的需求
\documentclass{article}
\usepackage{xcolor}
\usepackage{wrapfig}
\usepackage{setspace} % set space between lines
\usepackage{ragged2e} % ragged text and allow hyphenation
\usepackage{environ} % new environment
\usepackage{tcolorbox} % colorful boxes
\usepackage{blindtext} % just for testing
\usepackage{hyperref}
\newcounter{notecounter} % counter for notes
\NewEnviron{enote}
{%
\refstepcounter{notecounter} % increment note counter
\begin{singlespace} % single space at notes (optional)
\begin{tcolorbox}[%
colframe=red!50!yellow!50!black,
colback=red!50!yellow!5!white,
coltitle=red!50!yellow!3!white,
fonttitle=\small\sffamily\bfseries,
fontupper=\small,
fontlower=\small,
left=0mm,
right=0mm,
top=0mm,
bottom=0mm,
middle=2pt,
boxsep=1mm,
arc=0mm,
boxrule=0.5pt,
leftrule=3mm,
%title=Note~\thenotecounter\label{note:\thenotecounter}
]
\noindent Note~\thenotecounter\label{note:\thenotecounter}
\tcblower
\sloppy\hyphenchar\font=\defaulthyphenchar\RaggedRight\BODY
\end{tcolorbox}
\end{singlespace}
}
\newcommand{\sidenote}[3]{%
\setlength{\wrapoverhang}{\marginparwidth}%
%\setlength{\columnsep}{0pt}%
\addtolength{\wrapoverhang}{\marginparsep}%
\begin{wrapfigure}{o}{#1}%
\begin{enote}%
#2
\end{enote}%
\end{wrapfigure}
#3$^\textrm{\scriptsize\ref{note:\thenotecounter}}$}
\begin{document}
\sidenote{10cm}{%
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
}{%
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
}
\blindtext
\sidenote{0.8\textwidth}{%
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
side side side side side side side side side
}{%
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
text text text text text text text text text
}
\end{document}