首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在列表环境中使用多个latex (latex)配置标题

在列表环境中使用多个latex (latex)配置标题
EN

Stack Overflow用户
提问于 2010-10-20 20:06:33
回答 1查看 4.2K关注 0票数 4

我想在latex中做一个双列代码,但是在这两列上面有标题。例如:

代码语言:javascript
复制
  Program 1 : some text here for the caption

1   //col 1              7    //col2
2   void main (void)     8   void foo(void)
3   {                    9   {
4      //just a test    10      int c;
5      return 0;        11      c = 0;
6   }                   12   }

我使用的是列表。为了完成上面的布局,我在一个表中插入了两个列表。这种方法有一些问题,我必须手动划分代码并在PDF中观察结果。

我想使用multicol=2选项,但是在这种情况下,标题堆栈仅在第一列上。现在有谁能克服(如果可能的话)?

代码语言:javascript
复制
    Program 1 : some text 7    //col2
    here for the caption  8   void foo(void)
1   //col 1               9   {
2   void main (void)     10      int c;
3   {                    11      c = 0;
4      //just a test     12   }
5      return 0;         
6   }                    

下面是不工作的代码

代码语言:javascript
复制
\documentclass{article}
\usepackage{listings}
\usepackage{multicol}
\begin{document}

\lstset{
   language=C,
   breaklines=true,
   prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
}

\begin{lstlisting}[stepnumber=1,multicols=2,caption=Caption test to confirm that multicol does not like large captions]
void MudaDigito(char val)
{
   if (pos == 0)
   {
     v0 = val;
   }
   if (pos == 1)
   {
     v1 = val;
   }
   if (pos == 2)
   {
     v2 = val;
   }
   if (pos == 3)
   {
     v3 = val;
   }
}
\end{lstlisting}

结束{文档}

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-12-27 15:41:13

我也有同样的问题。我找到了解决办法。它不干净,但能用。下面是工作代码。

代码语言:javascript
复制
\documentclass{article}
\usepackage{listings}
\usepackage{multicol}
\newcommand{\listingcaption}[1]%
{%
\refstepcounter{lstlisting}\hfill%
Listing \thelstlisting -- #1\hfill%\hfill%
}%
\begin{document}
\lstset{
   language=C,
   breaklines=true,
   prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
}
\listingcaption{Caption test to confirm that multicol does not like large captions\label{list1}}
\begin{lstlisting}[stepnumber=1,multicols=2]
void MudaDigito(char val)
{
   if (pos == 0)
   {
     v0 = val;
   }
   if (pos == 1)
   {
     v1 = val;
   }
   if (pos == 2)
   {
     v2 = val;
   }
   if (pos == 3)
   {
     v3 = val;
   }
}
\end{lstlisting}
See listing \ref{list1}
\end{document}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3981837

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档