我尝试为列表添加边注(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}