Configurer légende sur l'environnement des listes en utilisant Multicol (latex)

StackOverflow https://stackoverflow.com/questions/3981837

  •  09-10-2019
  •  | 
  •  

Question

Je veux faire un code à double colonne en latex, mais avec la légende au-dessus des deux colonnes. 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   }

J'utilise annonces . Pour réaliser la mise en page ci-dessus, je coupe en deux listes à l'intérieur d'une table. Il y a quelques problèmes avec cette approche, je dois diviser manuellement le code et montre le résultat dans le PDF.

Je voudrais utiliser l'option [Multicol = 2], mais avec cela, la pile de sous-titres uniquement sur la première colonne. Est-ce que quelqu'un maintenant comment surmonter (si 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   }                    

Juste en dessous est le code non de travail

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

Était-ce utile?

La solution

i eu le même problème. J'ai trouvé une solution. Ce n'est pas propre, mais cela fonctionne. Juste au-dessous est le code de travail.


\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}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top