我有一个代码块,我想使用 verbatim 包在乳胶中显示它,但我想自定义代码行编号,而不是从 1 开始。这是我所关心的乳胶代码的示例:
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}[numbers=left,xleftmargin=5mm]
//Initial matrix alignment for A and B
int shift_source, shift_destination;
MPI_Cart_shift(row_communicator, 0, -coordinates[0], &shift_source, &shift_destination);
MPI_Sendrecv_replace(A_local_block, A_local_block_size, MPI_DOUBLE, shift_destination, 0,
shift_source, 0, row_communicator, &status);
MPI_Cart_shift(column_communicator, 0, -coordinates[1], &shift_source, &shift_destination);
MPI_Sendrecv_replace(B_local_block, B_local_block_size, MPI_DOUBLE,
shift_destination, 0,
shift_source, 0, column_communicator, &status);
// cannon's algorithm
.
.
.
.
MPI_Finalize();
}
\end{Verbatim}
\end{document}
我想要启动 verbatim 包来开始对行进行编号,比如从 200 开始,而不是从 1 开始。
有任何想法吗 ?
答案1
您可以指定该firstnumber
选项。
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{Verbatim}[numbers=left,xleftmargin=5mm,firstnumber=200]
//Initial matrix alignment for A and B
int shift_source, shift_destination;
MPI_Cart_shift(row_communicator, 0, -coordinates[0], &shift_source, &shift_destination);
MPI_Sendrecv_replace(A_local_block, A_local_block_size, MPI_DOUBLE, shift_destination, 0,
shift_source, 0, row_communicator, &status);
MPI_Cart_shift(column_communicator, 0, -coordinates[1], &shift_source, &shift_destination);
MPI_Sendrecv_replace(B_local_block, B_local_block_size, MPI_DOUBLE,
shift_destination, 0,
shift_source, 0, column_communicator, &status);
// cannon's algorithm
.
.
.
.
MPI_Finalize();
}
\end{Verbatim}
\end{document}
答案2
另一种方法是verbatimbox
:
\documentclass{article}
\usepackage{verbatimbox}
\begin{document}
\begin{verbbox}[{\rmfamily\tiny\the\numexpr200+\value{VerbboxLineNo}\relax}\quad\scriptsize]
//Initial matrix alignment for A and B
int shift_source, shift_destination;
MPI_Cart_shift(row_communicator, 0, -coordinates[0], &shift_source, &shift_destination);
MPI_Sendrecv_replace(A_local_block, A_local_block_size, MPI_DOUBLE, shift_destination, 0,
shift_source, 0, row_communicator, &status);
MPI_Cart_shift(column_communicator, 0, -coordinates[1], &shift_source, &shift_destination);
MPI_Sendrecv_replace(B_local_block, B_local_block_size, MPI_DOUBLE,
shift_destination, 0,
shift_source, 0, column_communicator, &status);
// cannon's algorithm
.
.
.
.
MPI_Finalize();
}
\end{verbbox}
\hspace{5mm}\theverbbox
\end{document}