使用 multicol (latex) 在列表环境中配置标题

发布于 2024-09-28 05:08:31 字数 1387 浏览 5 评论 0原文

我想在乳胶中制作双列代码,但标题位于两列上方。例如:

  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] 选项,但这样,标题堆栈仅在第一列上。现在有人如何克服(如果可能的话?)

    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   }                    

下面是非工作代码

\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}

\end{document}

I want to make a dual column code in latex but with the caption above the two columns. Ex:

  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   }

I'm using listings. To accomplish the layout above, I cut in two listings inside one table. There are some problems with this approach, I have to manually divide the code and watch for the result in the PDF.

I'd like to use [multicol=2] option, but with this, the caption stack only on the first column. Does anyone now how to overcome (if possible?)

    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   }                    

Just below is the non working code

\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}

\end{document}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡紫姑娘! 2024-10-05 05:08:31

我有同样的问题。我找到了解决方案。
它不干净,但有效。
下面是工作代码。


\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}

i had the same problem. I found a solution.
It's not clean but it works.
Just below is the working code.


\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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文