在LSTNewenvrientment之前添加新产品线
我正在使用lstNewenvironment
listings 软件包来创建新的代码块。 使用手册中的示例:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill pascal \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
这会生成pascal
代码块,例如: 在此处输入映像
现在我想在代码行上方添加一些文本为'tag'(在该行的末尾)类似:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill{\tiny pascal} \lstset{language=pascal}}
{}
这生成: 在此处输入图像描述
标签文本在同一行中与先前的文本,所以我添加<<<代码> \\ 在标签之前:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
并尝试过
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hspace{\textwidth}{\tiny pascal} \lstset{language=pascal}}
{}
,但是hfill
和\ hspace {\ textWidth}
不起作用,该标签出现在以上行的开始: 在此处输入图像说明
我唯一可以做的方法是在代码块之间手动添加空白行和先前的文字:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
输出: 在此处输入图像说明
我的问题是如何修改\ lstnewenvorment
设置,以便它可以在代码块和上一个文本之间自动添加新的界限,并在该新行的末尾使用标签?
I'm using lstnewenvironment
from the listings
package to create new code blocks.
Using an example from its manual:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill pascal \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
This generates a pascal
code block like:
enter image description here
Now I want to add some text as 'tag' above the code line (at the end of that line) like:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{\hfill{\tiny pascal} \lstset{language=pascal}}
{}
This generates:
enter image description here
The tag text is at the same line with previous text, so I add \\
before the tag:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
And tried
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \\ \hspace{\textwidth}{\tiny pascal} \lstset{language=pascal}}
{}
But both of the hfill
and \hspace{\textwidth}
don't work, the tag appears at the beginning of the line above:
enter image description here
The only way I can do is manually adding a blank line between the code block and previous text:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\lstnewenvironment{pascal}
{ \hfill{\tiny pascal} \lstset{language=pascal}}
{}
\begin{document}
some text before code block
\begin{pascal}
for i := maxint to 0 do
begin
{ do nothing}
end;
\end{pascal}
\end{document}
Output:
enter image description here
My question is how to modify the \lstnewenvironment
settings so that it can automatically add a new line between the code block and the previous text, with a tag at the end of that new line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
参见 https://tex.stac.stackexchange.com/a/625934/36296
see https://tex.stackexchange.com/a/625934/36296