我想要在 itemize 环境的项目中打印一段逐字记录,如下所示:
\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}
\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}
\begin{document}
\section*{Problem \#1}
\Question{content
}
\Answer{
\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV
PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}
但是有一个错误:
! Paragraph ended before \lst@next was complete
。
我甚至尝试过frame
解决方案,这里,但它仍然不起作用:
\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}
\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}
\begin{document}
\section*{Problem \#1}
\Question{content
}
\Answer{
\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{frame}[fragile]
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV
PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{frame}
\end{itemize}
}
\end{document}
答案1
因为似乎有一个绝对的决不对于代码改进(包括更改宏)和手动执行一些操作(包括编号),没有什么可以做的。
\documentclass[letter, 11pt]{article}
\usepackage{enumitem}
\usepackage{pifont}
\usepackage{listings}
\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}
\newcommand{\Answer}{\noindent\ding{51}: }
\begin{document}
\section*{Problem \#1}
\Question{content
}
\Answer{
\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G =
VVVVVVVVVVVVVVVVVVVVVVVVVVV
PROJ
=
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}
答案2
[fragile]
这不是 OP 问题的答案,但是当我在添加代码时忘记添加到我的框架时遇到了这个问题lstlisting
。
例子:
破碎的
\begin{frame}
\begin{lstlisting}[language=Java]
// single line comment
\end{lstlisting}
\end{frame}
固定的
\begin{frame}[fragile]
\begin{lstlisting}[language=Java]
// single line comment
\end{lstlisting}
\end{frame}
答案3
对我来说,使用 \input 的解决方法也有效。
当我尝试在 multiaudience 包中使用 lstlistings 时遇到了相同的错误消息:
\usepackage{multiaudience}
\SetNewAudience{guests}
\begin{shownto}{guests}
\begin{indentcode}
\begin{lstlisting}
some text
\end{lstlisting}
\end{indentcode}
\end{shownto}
~~~~~~~ example which works ~~~~~~~~~
\usepackage{multiaudience}
\SetNewAudience{guests}
\begin{shownto}{guests}
\begin{indentcode}
\input{folder/newfile}
\end{indentcode}
\end{shownto}
with the content of newfile.tex being saved in the 'folder':
\begin{lstlisting}
some text
\end{lstlisting}
答案4
什么能你控制这里吗?
问题在于将逐字环境作为命令的参数。从这个问题,一个解决方案是使用cprotect
:
\documentclass[letter, 11pt]{article}
\usepackage{enumitem,cprotect}
\usepackage{pifont}
\usepackage{listings}
\newcommand{\Question}[1]{{\bfseries?: #1\par\vspace{5pt}}}
\newcommand{\Answer}[1]{\noindent\ding{51}: #1}
\begin{document}
\section*{Problem \#1}
\Question{content
}
\cprotect\Answer{
\begin{itemize}
\item[1] Some content.\\
My Verbatim:
\begin{lstlisting}
G = VVVVVVVVVVVVVVVVVVVVVVVVVVV
PROJ = PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
\end{lstlisting}
\end{itemize}
}
\end{document}