我想要一个带编号的边际查询标记列表。我的尝试(如下)正确地给出了边际标记???1 和???2,但 itemize 环境中的增量似乎丢失了,下一个查询也被标记为???2。
\documentclass{report}
\newcount\countahhqqq
\countahhqqq=0
\def\QQ{ \advance \countahhqqq by 1 \marginpar{\bf ???\number\countahhqqq}}
\begin{document}
Here I raise a question\QQ and get a numbered marginal note.
Now in an itemize environment
\begin{itemize}
\item I'm happy here
\item but less so here\QQ
\end{itemize}
which leaves me wondering what's gone wrong.\QQ
\end{document}
答案1
计数器值的更改是作用域内的本地更改,因此在 之后重置itemize
。解决方法是在计数器前进之前使用\global
:
\global\advance \countahhqqq by 1
\newcounter
这是 LaTeX 通过和定义和步进计数器时自然所做的事\stepcounter
。
\documentclass{article}
%\newcount\countahhqqq
%\countahhqqq=0
%\def\QQ{\global\advance \countahhqqq by 1 \marginpar{\bf ???\number\countahhqqq}}
\newcounter{countahhhqqq}
\newcommand{\QQ}{\stepcounter{countahhhqqq}\marginpar{\bfseries ???\thecountahhhqqq}}
\begin{document}
Here I raise a question\QQ{} and get a numbered marginal note.
Now in an itemize environment
\begin{itemize}
\item I'm happy here
\item but less so here\QQ
\end{itemize}
which leaves me wondering what's gone wrong.\QQ
\end{document}