Latex中的列表样式列表
List of listing style in Latex
我尝试创建一个列表,在我的乳胶文档中列出我的代码片段
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\usepackage{listings}
\renewcommand\lstlistingname{Code}
\renewcommand\lstlistlistingname{List of code snippets}
\title{Code Listing}
\begin{document}
\maketitle
\section{Code examples}
\begin{listing}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
import numpy as np
def incmatrix(genl1,genl2):
m = len(genl1)
n = len(genl2)
M = None #to become the incidence matrix
VT = np.zeros((n*m,1), int) #dummy variable
#compute the bitwise xor matrix
M1 = bitxormatrix(genl1)
M2 = np.triu(bitxormatrix(genl2),1)
for i in range(m-1):
for j in range(i+1, m):
[r,c] = np.where(M2 == M1[i,j])
for k in range(len(r)):
VT[(i)*n + r[k]] = 1;
VT[(i)*n + c[k]] = 1;
VT[(j)*n + r[k]] = 1;
VT[(j)*n + c[k]] = 1;
if M is None:
M = np.copy(VT)
else:
M = np.concatenate((M, VT), 1)
VT = np.zeros((n*m,1), int)
return M
\end{minted}
\caption{Example of code}
\label{lst:code1}
\end{listing}
\clearpage
\lstlistoflistings
\end{document}
我不知道为什么我的列表是这样的:
我在 minted 下的标题应更改为代码 1:代码示例
字幕解决方案
替换为:
\renewcommand\lstlistingname{代码}
至:
\renewcommand{\listingscaption}{代码}
我读了很多 post 但仍然没有找到解决方案.. :(
如有任何帮助,我将不胜感激
首先,像这样的问题应该在 tex.stackexchange 上提出。
至于问题本身,您在这里混用了两个包。 minted
与 listings
是分开的,因此后者的命令在前者的环境中运行异常(从技术上讲,它们根本不应该运行,但我们正在谈论的是 TeX)。根据 minted
的 docs,这就是你应该做的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted} % don't need to import `listing` or `listings`
% custom labels, according to the docs
\renewcommand\listingscaption{Code}
\renewcommand\listoflistingscaption{List of code snippets}
\title{Code Listing}
\begin{document}
\maketitle
\section{Code examples}
\begin{listing}[H] % creates a float
\begin{minted} % does the syntax highlighting
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
your_code(...)
\end{minted}
\caption{Example of code}
\label{lst:code1}
\end{listing}
This is a reference to Code~\ref{lst:code1} to make it appear in the list of listings.
\clearpage
\listoflistings % NOT `lstlistoflistings`
\end{document}
结果:
我尝试创建一个列表,在我的乳胶文档中列出我的代码片段
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted}
\usepackage{listings}
\renewcommand\lstlistingname{Code}
\renewcommand\lstlistlistingname{List of code snippets}
\title{Code Listing}
\begin{document}
\maketitle
\section{Code examples}
\begin{listing}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
import numpy as np
def incmatrix(genl1,genl2):
m = len(genl1)
n = len(genl2)
M = None #to become the incidence matrix
VT = np.zeros((n*m,1), int) #dummy variable
#compute the bitwise xor matrix
M1 = bitxormatrix(genl1)
M2 = np.triu(bitxormatrix(genl2),1)
for i in range(m-1):
for j in range(i+1, m):
[r,c] = np.where(M2 == M1[i,j])
for k in range(len(r)):
VT[(i)*n + r[k]] = 1;
VT[(i)*n + c[k]] = 1;
VT[(j)*n + r[k]] = 1;
VT[(j)*n + c[k]] = 1;
if M is None:
M = np.copy(VT)
else:
M = np.concatenate((M, VT), 1)
VT = np.zeros((n*m,1), int)
return M
\end{minted}
\caption{Example of code}
\label{lst:code1}
\end{listing}
\clearpage
\lstlistoflistings
\end{document}
我不知道为什么我的列表是这样的:
我在 minted 下的标题应更改为代码 1:代码示例
字幕解决方案
替换为: \renewcommand\lstlistingname{代码}
至: \renewcommand{\listingscaption}{代码}
我读了很多 post 但仍然没有找到解决方案.. :(
如有任何帮助,我将不胜感激
首先,像这样的问题应该在 tex.stackexchange 上提出。
至于问题本身,您在这里混用了两个包。 minted
与 listings
是分开的,因此后者的命令在前者的环境中运行异常(从技术上讲,它们根本不应该运行,但我们正在谈论的是 TeX)。根据 minted
的 docs,这就是你应该做的:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{minted} % don't need to import `listing` or `listings`
% custom labels, according to the docs
\renewcommand\listingscaption{Code}
\renewcommand\listoflistingscaption{List of code snippets}
\title{Code Listing}
\begin{document}
\maketitle
\section{Code examples}
\begin{listing}[H] % creates a float
\begin{minted} % does the syntax highlighting
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
fontsize=\footnotesize,
linenos
]
{python}
your_code(...)
\end{minted}
\caption{Example of code}
\label{lst:code1}
\end{listing}
This is a reference to Code~\ref{lst:code1} to make it appear in the list of listings.
\clearpage
\listoflistings % NOT `lstlistoflistings`
\end{document}
结果: