![我怎样才能将代码列表放入 tikzposter \block 中?](https://linux22.com/image/305784/%E6%88%91%E6%80%8E%E6%A0%B7%E6%89%8D%E8%83%BD%E5%B0%86%E4%BB%A3%E7%A0%81%E5%88%97%E8%A1%A8%E6%94%BE%E5%85%A5%20tikzposter%20%5Cblock%20%E4%B8%AD%EF%BC%9F.png)
我试图在我的海报中放入代码列表,但是出现以下错误:
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}