边注扰乱了清单的行号

边注扰乱了清单的行号

我尝试为列表添加边注(PS:脚注很好用),但是当打开行号时,边注会扰乱数字:

\documentclass{article}

\usepackage{listings}
\usepackage{marginnote}

\begin{document}

\lstset{language=C++,numbers=left,escapeinside={(*@}{@*)}}

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
    cout << i << endl;
}
\end{lstlisting}

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
    cout << i << endl;(*@\marginnote{margin note}@*)
}
\end{lstlisting}

%% I've tried to wrap \marginnote with boxes, but could't fix it.

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
    cout << i << endl;(*@\vbox{\marginnote{margin note}}@*)
}
\end{lstlisting}

\end{document}

结果

答案1

如果该包marginnote不是强制性的,\marginpar则执行以下工作:

\documentclass{article}

\usepackage{listings}
%\usepackage{marginnote}

\begin{document}

\lstset{language=C++,numbers=left,escapeinside={(*@}{@*)}}

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
    cout << i << endl;
}
\end{lstlisting}

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
 cout << i << endl;(*@\marginpar{margin note}@*)
}
\end{lstlisting}

%% I've tried to wrap \marginnote with boxes, but could't fix it.

\begin{lstlisting}
for (int i = 0; i < 10; i++)
{
cout << i << endl;(*@\marginpar{margin note}@*)
}
\end{lstlisting}

\end{document}

在此处输入图片描述

相关内容