我想做一些与行号类似但不完全相同的事情:
宏\foo
定义foocounter
在环境中,并作为计数器foonumber
。使用宏时,foocounter
增加 1,然后打印在使用宏的行的左边距。如果一行中使用了不止一次宏,foocounter
则应全部打印在左边距,并用空格隔开。
这描述了我想要做的事情,但我不知道如何在左边距打印计数器。
此外,我正在使用multicol
两列。我希望计数器打印在每列的左侧。(相比之下,行号通常会将数字打印在外边距上。)
2014 年 7 月 14 日添加
我在下面的代码中编写了一个宏 \foo。这似乎是成功的,但数字的最后一次出现会跳转到下一页。最后一页没有下一页,数字消失了。有人能修复它吗?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\temppp{}
\newcounter{BAR}
\newcommand\foo{\stepcounter{BAR}$^{\arabic{BAR}}$\tikz[remember picture,overlay]\path let\p1=(current page.west),\p2=(X)in(\x1,0)coordinate(X)+(120pt,\y2)node[above left]{\ifdim\y2=0pt\global\edef\temppp{\temppp~\hbox{\arabic{BAR}}}\else\scriptsize\temppp\global\edef\temppp{\hbox{\arabic{BAR}}}\fi};}
\begin{document}
\hbox to 0pt{\tikz[remember picture]\node(X){};}%Put an X at the start
\foo Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \foo Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. \foo Curabitur dictum gravida mauris. \foo Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. \foo Donec vehicula augue eu neque. \foo Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. \foo Mauris ut leo. \foo Cras viverra metus rhoncus sem. \foo Nulla et lectus vestibulum urna fringilla ultrices. \foo Phasellus eu tellus sit amet tortor gravida placerat. \foo Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. \par
\vskip 360pt \foo Praesent eget sem vel leo ultrices bibendum. \foo Aenean faucibus. \foo Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. \foo Curabitur auctor semper nulla. \foo Donec varius orci eget risus. \foo Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. \foo Duis eget orci sit amet orci dignissim rutrum. \foo Lorem ipsum dolor sit amet, consectetuer adipiscing elit. \foo Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. \foo Curabitur dictum gravida mauris. \foo Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. \foo Donec vehicula augue eu neque. \foo Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. \foo Mauris ut leo. \foo Cras viverra metus rhoncus sem. \foo Nulla et lectus vestibulum urna fringilla ultrices. \foo Phasellus eu tellus sit amet tortor gravida placerat. \foo Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. \par
\end{document}
答案1
尝试一下marginnote
。但这不适multicols
用于你自找的. 而且它也不适用于on left side
需求。
\documentclass[twoside]{scrreprt}
\usepackage[fulladjust]{marginnote}
\usepackage[a4paper,left=1in,right=2in,marginparwidth=1in,marginparsep=0.1in,showframe]{geometry}
\newcounter{foocounter}
\setcounter{foocounter}{0}
\newcommand\foo[1]{%
\refstepcounter{foocounter}
\marginnote{\thefoocounter}\emph{#1}
}
\usepackage{multicol}
\begin{document}
This is a\foo{goes to side} side note.
\newpage
\begin{multicols}{2}
Some text and another me and you one which is not here but some where else and its mark is alone here.
But here \foo{go to the side and span more than one line if possible}
\end{multicols}
\end{document}