我试图在我的海报中放入代码列表,但是出现以下错误:
TeX 容量超出,抱歉 [输入堆栈大小=5000]
我究竟做错了什么?
\documentclass[portrait, a0paper, 25pt]{tikzposter}
\title{title}
\author{}
\institute{}
\usepackage{color}
\definecolor{bluekeywords}{rgb}{0.13,0.13,1}
\definecolor{greencomments}{rgb}{0,0.5,0}
\definecolor{redstrings}{rgb}{0.9,0,0}
\usepackage{listings}
\lstset{language=[Sharp]C,
showspaces=false,
showtabs=false,
breaklines=true,
showstringspaces=false,
breakatwhitespace=true,
escapeinside={(*@}{@*)},
commentstyle=\color{greencomments},
keywordstyle=\color{bluekeywords}\bfseries,
stringstyle=\color{redstrings},
basicstyle=\ttfamily
}
\begin{document}
\maketitle
\block{Block title}{
\begin{lstlisting}
%some code
\end{lstlisting}
}
\end{document}
\endinput
答案1
不...代码格式-...格式化...什么..所以...无论如何...我都要...死...
更严重的问题是,环境中的内容lstlisting
被处理逐字,这意味着您不能在命令的参数中拥有这样的环境(\block
,此处)。
一种常见的解决方法是将列表写入外部文件(带有或不带有包filecontents
)并使用命令插入\lstinputlisting
,而不是将列表嵌入lstlisting
环境内。
\documentclass[portrait, a0paper, 25pt]{tikzposter}
\title{title}
\author{}
\institute{}
\usepackage{color}
\definecolor{bluekeywords} {rgb}{0.13, 0.13, 1}
\definecolor{greencomments}{rgb}{0 , 0.5 , 0}
\definecolor{redstrings} {rgb}{0.9 , 0, 0}
\usepackage{listings}
\lstset{
language = [Sharp]C,
showspaces = false,
showtabs = false,
breaklines = true,
showstringspaces = false,
breakatwhitespace = true,
escapeinside = {(*@}{@*)},
commentstyle = \color{greencomments},
keywordstyle = \color{bluekeywords}\bfseries,
stringstyle = \color{redstrings},
basicstyle = \ttfamily,
}
% -----
% the following writes to an external file called 'foo.hs'
\usepackage{filecontents}
\begin{filecontents*}{foo.hs}
fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
\end{filecontents*}
% -----
\begin{document}
\maketitle
\block{Block title}{%
\lstinputlisting{foo.hs}
}
\end{document}