我正在尝试创建一些类似marginpar
但没有浮点数麻烦的东西(特别是因为我将会拥有很多这样的浮点数)。
首要问题这些注释总是出现在段落的开头,我希望能够考虑段落是否已缩进(例如它是否跟在section
)。我真的只需要知道这一点,这样我就可以正确地将注释定位在右边距中。我想tikz
这可能有点窍门。如果您知道一个,我将非常感激您对找到当前行右边距位置的建议。我也对非答案非常感兴趣tikz
。
第二期我希望能够消除环境后面多余的空格。我知道我可以%
在环境后面手动添加。但我不想这么做。我想使用etoolbox
钩子可以实现这种效果\AtEndEnvironment
,但那行不通。
这是 MWE
\documentclass{article}
\usepackage[driver=dvips,
top=0.5in,bottom=0.5in,
left=0.5in,right=3.25in,
headsep=0.5\baselineskip, headheight=\baselineskip,
footskip=1.5\baselineskip,
]{geometry}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{etoolbox}
\usepackage{lipsum}
%%'
\newsavebox{\aemarginpar}
\newenvironment{mnote}
{%
\begin{lrbox}{\aemarginpar}\color{blue}%
\begin{minipage}[t]{\dimexpr 3.25in - 2em - 0.5in\relax}%\raggedright%
}{%
\end{minipage}%
\end{lrbox}%
\rule{0pt}{0pt}%
\hspace*{\linewidth}%
\raisebox{0pt}[0pt][0pt]{%
\makebox[0pt][l]{\hspace*{2em}\usebox{\aemarginpar}}%
}%
\hspace*{-\linewidth}%
}
\AtEndEnvironment{mnote}{\ignorespaces}
\begin{document}
\section{Hello}
\begin{mnote}
First margin note. I want to kill white space at the end of the
environment, but even with \verb=etoolbox=, I can't seem to get rid of
the extra white space.
\end{mnote}
\lipsum[1-2]
\begin{mnote}
My margin note is pushed too far to the left which is, of course,
because the paragraph has been indented.
\end{mnote}
\lipsum[3-4]
\end{document}
结果如下:
答案1
用于\ignorespacesafterend
忽略后面的空格\end
。根据要求,这只会将框添加为定位,但如果段落靠近页面底部,它当然会超出页面,这就是标准边距被设计为移动的原因。
\documentclass{article}
\usepackage[%driver=dvips,
top=0.5in,bottom=0.5in,
left=0.5in,right=3.25in,
headsep=0.5\baselineskip, headheight=\baselineskip,
footskip=1.5\baselineskip,
]{geometry}
\pagestyle{empty}
\usepackage{xcolor}
\usepackage{lipsum}
%%'
\newsavebox{\aemarginpar}
\newenvironment{mnote}
{%
\begin{lrbox}{\aemarginpar}\color{blue}%
\begin{minipage}[t]{\dimexpr 3.25in - 2em - 0.5in\relax}%\raggedright%
}{%
\end{minipage}%
\end{lrbox}%
\leavevmode\strut\vadjust{%
\smash{\raise\dp\strutbox\hbox{%
\kern\dimexpr\textwidth+\marginparsep\relax
\usebox{\aemarginpar}}}}%
\ignorespacesafterend}
\begin{document}
\section{Hello}
\begin{mnote}
First margin note. I want to kill white space at the end of the
environment, but even with \verb=etoolbox=, I can't seem to get rid of
the extra white space.
\end{mnote}
\lipsum[1-2]
\begin{mnote}
My margin note is pushed too far to the left which is, of course,
because the paragraph has been indented.
\end{mnote}
\lipsum[3-4]
\end{document}