我正在尝试创建一个双面文档,其外边距包含边距注释。外边距区域具有彩色背景,例如灰色。每个边距注释应该与指向内部的小箭头/三角形相关联,从边距注释指向注释相关的正文行。
现在,关键是小箭头应该有一个(垂直延伸的)底部,与页边距区域的(也是垂直延伸的)内边缘平齐。我设法让这个功能在左页上工作,但在右页上却不行。似乎边注始终使用边距区域的左边缘来水平定位注释,并且小三角形会在右页上引起问题,因为它的点始终靠在左边缘(从而将注释框架推到右方,离开边距区域)。
无论如何,这就是我试图实现的目标(左页):
而我在正确的页面上看到的内容如下:
我的代码到目前为止看起来像这样:
\documentclass[9pt]{extbook}
% --------------------------
% Packages
% --------------------------
\usepackage{xparse}
\usepackage{calc}
\usepackage{marginnote}
\usepackage[x11names,dvipsnames]{xcolor}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{background}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[backgroundcolor=gray!40,%
hidealllines=true,%
roundcorner=5pt,%
skipabove=15pt,%
skipbelow=15pt,%
leftmargin=0cm,%
rightmargin=0cm,%
innertopmargin=5pt,%
innerbottommargin=5pt,%
innerleftmargin=5pt,%
innerrightmargin=5pt,%
framemethod=tikz%
]{mdframed}%
% --------------------------
% Page geometry
% --------------------------
\usepackage[includemp,
twoside,
marginparwidth=45mm,
marginparsep=5mm]{geometry}
% --------------------------
% Color the margins
% --------------------------
\backgroundsetup{%
scale=1,%
angle=0,%
contents={\tikz[remember picture,overlay]\fill[gray!80] (current page marginpar area.north west) rectangle (current page marginpar area.south east);}%
}
% --------------------------
% Margin notes
% --------------------------
\newlength{\mnvoffset}%
\newcommand{\mn}[2]{%
\leavevmode%
\setlength{\mnvoffset}{#1pt - 29.5pt}%
\marginnote[{\begin{mdframed}[singleextra={\fill[black] ( $ (P) + (0,-11pt + #1pt) $ ) -- +(3pt,3pt) -- +(0,6pt) -- cycle;}]\sloppy\small#2\end{mdframed}}]%
{\begin{mdframed}[singleextra={\fill[black] ( $ (P-|O) + (0,-11pt + #1pt) $ ) -- +(-3pt,3pt) -- +(0,6pt) -- cycle;}]\sloppy\small#2\end{mdframed}}[\mnvoffset]%
}
\begin{document}
\blindtext
\mn{0}{Test}
\blindtext
\newpage
\blindtext
\mn{0}{Test}
\blindtext
\end{document}
是否可以修复代码以实现预期的效果,或者我应该尝试一种完全不同的方法?
答案1
以下是一种非常棘手的方法,但似乎可以给出预期的结果(不过您应该测试一下……):
\documentclass[9pt]{extbook}
% --------------------------
% Packages
% --------------------------
\usepackage{xparse}
\usepackage{calc}
\usepackage{marginnote}
\usepackage[x11names,dvipsnames]{xcolor}
\usepackage{tikzpagenodes}
\usetikzlibrary{calc}
\usepackage{background}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage[backgroundcolor=gray!40,%
hidealllines=true,%
roundcorner=5pt,%
skipabove=15pt,%
skipbelow=15pt,%
leftmargin=0cm,%
rightmargin=0cm,%
innertopmargin=5pt,%
innerbottommargin=5pt,%
innerleftmargin=5pt,%
innerrightmargin=5pt,%
framemethod=tikz%
]{mdframed}%
% --------------------------
% Page geometry
% --------------------------
\usepackage[includemp,
showframe,
twoside,
marginparwidth=45mm,
marginparsep=5mm]{geometry}
% --------------------------
% Color the margins
% --------------------------
\backgroundsetup{%
scale=1,%
angle=0,%
contents={\tikz[remember picture,overlay]\fill[gray!80] (current page marginpar area.north west) rectangle (current page marginpar area.south east);}%
}
% --------------------------
% Margin notes
% --------------------------
\newlength{\mnvoffset}%
\newcommand{\mn}[2]{%
\leavevmode%
\setlength{\mnvoffset}{#1pt - 29.5pt}%
\marginnote[{\begin{mdframed}[singleextra={\fill[black] ( $ (P) + (0,-11pt + #1pt) $ ) -- +(3pt,3pt) -- +(0,6pt) -- cycle;}]\sloppy\small#2\end{mdframed}}]%
{\hspace*{-3pt}\parbox[t]{\marginparwidth}{\strut\begin{mdframed}[singleextra={\fill[black] ( $ (P-|O) +
(0,-11pt + #1pt) $ ) -- +(-3pt,3pt) -- +(0,6pt) --
cycle;}]\sloppy\small#2\end{mdframed}}}[\mnvoffset]%
}
\begin{document}
\blindtext
\mn{0}{Test}
\blindtext
\newpage
\blindtext
\mn{0}{Test}
\blindtext
\end{document}