英文:
Latex "listings" doesn't show code inside single and double quotation
问题
这是我的项目的一个简单示例,在这里我使用了这段R代码:
\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{listings}
\usepackage{color}
\lstset{
language=R,
basicstyle=\footnotesize\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
tabsize=4,
extendedchars=true,
breaklines=true,
keywordstyle=\textbf,
stringstyle=\color{white}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
"尝试双引号内的文字"
'尝试单引号内的文字'
airportsData <- read.csv("dataset\\airports.txt", header = FALSE, sep = ",", quote = "\"")
colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
\end{lstlisting}
\end{document}
当我编译结果时:
正如您所见,它不显示引号内的代码。
英文:
Here's a minimal example of my project, where I use this R code:
\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{listings}
\usepackage{color}
\lstset{
language=R,
basicstyle=\footnotesize\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
tabsize=4,
extendedchars=true,
breaklines=true,
keywordstyle=\textbf,
stringstyle=\color{white}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
"Try words inside double quotes"
'Try words inside single quotes'
airportsData <- read.csv("dataset\airports.txt", header = FALSE, sep = ",", quote = "\"")
colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
\end{lstlisting}
\end{document}
And when I compile the result is:
As you can see, it doesn't show the code between quotes.
答案1
得分: 0
You set the colour for strings to white. Choose any other colour if you use it on a white paper...
\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{listings}
\usepackage{color}
\lstset{
language=R,
basicstyle=\footnotesize\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
tabsize=4,
extendedchars=true,
breaklines=true,
keywordstyle=\textbf,
stringstyle=\color{red}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
"Try words inside double quotes"
'Try words inside single quotes'
airportsData <- read.csv("dataset\airports.txt", header = FALSE, sep = ",", quote = "\"")
colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
\end{lstlisting}
\end{document}
英文:
You set the colour for strings to white. Choose any other colour if you use it on a white paper...
\documentclass[12pt,a4paper,openany,oneside]{book}
\usepackage{listings}
\usepackage{color}
\lstset{
language=R,
basicstyle=\footnotesize\ttfamily,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
tabsize=4,
extendedchars=true,
breaklines=true,
keywordstyle=\textbf,
stringstyle=\color{red}\ttfamily,
showspaces=false,
showtabs=false,
xleftmargin=17pt,
framexleftmargin=17pt,
framexrightmargin=5pt,
framexbottommargin=4pt,
showstringspaces=false
}
\begin{document}
\begin{lstlisting}
"Try words inside double quotes"
'Try words inside single quotes'
airportsData <- read.csv("dataset\airports.txt", header = FALSE, sep = ",", quote = "\"")
colnames(airportsData) <- c("openflightCode" , "name", "city", "country", "IATA", "ICAO", "latitude", "longitude", "altitude", "timezone", "DST", "tzdb", "type", "source")
\end{lstlisting}
\end{document}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论