列出页面外的代码

列出页面外的代码

我正在使用列表来显示我的代码。我遇到了一些问题。首先,代码太长时,它会超出页面,如图所示这里。其次,代码采用 SPARQL 语言编写。它识别出我用作 SQL 关键字的某些变量,并按如下所示突出显示它们这里在哪里班级尽管是变量,但被突出显示为关键字。 我的代码如下:

\begin{lstlisting}[captionpos=b, caption=Retrieval of Individuals, label=listing:sparql_getallindividuals,
   basicstyle=\ttfamily]
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  wo:   <http://purl.org/ontology/wo/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT  ?individual ?type ?name
  WHERE
    { ?individual rdf:type ?type .
      ?individual wo:commonName ?name
      FILTER ( ?type IN (wo:Kingdom, wo:Phylum, wo:Class, wo:Order, wo:Species, wo:Family, wo:Genus) )
    }
\end{lstlisting}

任何帮助将不胜感激

这是我的报告的序言:

\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

 \lstset{frame=tb,
  language=Java,
  showstringspaces=false,
  columns=flexible,
  numbers=none,
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  tabsize=3
}
\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type,ma-id}% list your attributes here
}

答案1

对于断线问题,您可以使用以下breaklines=true选项:

\documentclass{book}
\usepackage{listings}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}

 \lstset{frame=tb,
  language=Java,
  breaklines=true,
  showstringspaces=false,
  columns=flexible,
  numbers=none,
  commentstyle=\color{dkgreen},
  stringstyle=\color{mauve},
  tabsize=3
}
\lstdefinelanguage{XML}
{
  morestring=[b]",
  morestring=[s]{>}{<},
  morecomment=[s]{<?}{?>},
  stringstyle=\color{black},
  identifierstyle=\color{darkblue},
  keywordstyle=\color{cyan},
  morekeywords={xmlns,version,type,ma-id}% list your attributes here
}

\begin{document}

\begin{lstlisting}[captionpos=b, caption=Retrieval of Individuals, label=listing:sparql_getallindividuals,
   basicstyle=\ttfamily]
PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  wo:   <http://purl.org/ontology/wo/>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT  ?individual ?type ?name
  WHERE
    { ?individual rdf:type ?type .
      ?individual wo:commonName ?name
      FILTER ( ?type IN (wo:Kingdom, wo:Phylum, wo:Class, wo:Order, wo:Species, wo:Family, wo:Genus) )
    }
\end{lstlisting}

\end{document}

在此处输入图片描述

对于另一个问题,您没有提供足够的信息来检测问题。

相关内容