![在列表中添加引用](https://linux22.com/image/349331/%E5%9C%A8%E5%88%97%E8%A1%A8%E4%B8%AD%E6%B7%BB%E5%8A%A0%E5%BC%95%E7%94%A8.png)
我想在列表中引用一本书,但是这行不通。
这是完整的代码。有人能帮帮我吗?
\begin{singlespaced}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{blue},
keywordstyle=\color{red},
numberstyle=\tiny\color{black},
stringstyle=\color{codegreen},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\lstset{style=mystyle}
\begin{lstlisting}[language=FORTRAN, caption=MPI implementation in inter-process message exchange (Fortran).,Adapted from \cite{exe}, label=mpiexample1]
CHARACTER*20 msg
INTEGER myrank, ierr, status(MPI_STATUS_SIZE)
INTEGER tag = 99
...
CALL MPI_COMM_RANK( MPI_COMM_WORLD, myrank, ierr)
IF (myrank .EQ. 0) THEN
msg = "Hello there"
CALL MPI_SEND( msg, 11, MPI_CHARACTER, 1,
tag, MPI_COMM_WORLD, ierr)
ELSE IF (myrank .EQ. 1) THEN
CALL MPI_RECV( msg, 20, MPI_CHARACTER, 0,
tag, MPI_COMM_WORLD, status, ierr)
END IF
\end{lstlisting}
\end{singlespaced}
答案1
您的标题文字中似乎有一个逗号,因此您需要将其括起来。
该filecontents
环境仅作为示例使用。
\begin{filecontents*}{\jobname.bib}
@book{exe,
author={A. Uthor},
title={Title},
publisher={Publish or Perish},
year=2016,
}
\end{filecontents*}
\documentclass{article}
\usepackage{listings}
\usepackage{xcolor}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{blue},
keywordstyle=\color{red},
numberstyle=\tiny\color{black},
stringstyle=\color{codegreen},
basicstyle=\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
}
\begin{document}
\begin{lstlisting}[
language=FORTRAN,
style=mystyle,
caption={%
MPI implementation in inter-process message exchange (Fortran),
adapted from \cite{exe}%
},
label=mpiexample1
]
CHARACTER*20 msg
INTEGER myrank, ierr, status(MPI_STATUS_SIZE)
INTEGER tag = 99
...
CALL MPI_COMM_RANK( MPI_COMM_WORLD, myrank, ierr)
IF (myrank .EQ. 0) THEN
msg = "Hello there"
CALL MPI_SEND( msg, 11, MPI_CHARACTER, 1,
tag, MPI_COMM_WORLD, ierr)
ELSE IF (myrank .EQ. 1) THEN
CALL MPI_RECV( msg, 20, MPI_CHARACTER, 0,
tag, MPI_COMM_WORLD, status, ierr)
END IF
\end{lstlisting}
\bibliographystyle{plain}
\bibliography{\jobname}
\end{document}