在LaTeX中创建新环境的问题 [英] Problem with creating a newenvironment in LaTeX

查看:69
本文介绍了在LaTeX中创建新环境的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在LaTeX中实现这一新环境:

I am trying to implement this new environment in LaTeX:

\newenvironment{javacode}[2]
{\begin{lstlisting}[language=java, label=#1, caption=#2]}
{\end{lstlisting}}

然后像这样使用它:

\begin{javacode}{c}{some code}
int x = 5;
\end{javacode}

但是我遇到以下错误:

Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1] [2]) [3])
*

任何人都可以在解决此问题方面提供帮助吗?

Can anyone help as regards fixing this problem?

[更新]

我尝试过这样做红鼻子独角兽指示,并且可以正常工作.

I tried it doing it like Red-nosed unicorn instructed, and it worked correctly.

但是现在我尝试添加这样的\begin{singlespace}:

But now I tried adding a \begin{singlespace} like such:

\lstnewenvironment{javacode}[2]
{
\begin{singlespace}
\lstset{language=java, label=#1, caption=#2}}
{
\end{singlespace}
}

我遇到了同样的错误:

Overfull \hbox (6.0pt too wide) in paragraph at lines 6--6
[][][][][][][] 
[1]) [2] [3])
*

推荐答案

经进一步研究,我发现此

Upon further research, I found this http://www.tug.org/pipermail/texhax/2009-June/012699.html

要解决我的解决方案,我需要使用\singlespacing而不是singlespace环境.

To workaround my solution, I need to use \singlespacing instead of the singlespace environment.

以下是我的工作代码:

\lstnewenvironment{javacode}[2]
{\singlespacing\lstset{language=java, label=#1, caption=#2}}
{}

这篇关于在LaTeX中创建新环境的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆