在列表中添加引用

在列表中添加引用

我想在列表中引用一本书,但是这行不通。

这是完整的代码。有人能帮帮我吗?

\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}

在此处输入图片描述

相关内容