Frage

Ich mag einen Doppelsäule Code in Latex machen, aber mit der Beschriftung über den beiden Spalten. 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   }

Ich bin mit Inserate . Um das Layout zu erreichen oben, schnitt ich in zwei Auflistungen innerhalb einer Tabelle. Es gibt einige Probleme mit diesem Ansatz muss ich manuell den Code und die Uhr für das Ergebnis im PDF teilen.

Ich würde gerne verwenden [multicol = 2] Option, aber mit diesem, die Beschriftung Stapel nur auf der ersten Spalte. Hat jemand jetzt, wie zu überwinden (wenn möglich?)

    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 unten ist der nicht funktionierenden 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}

War es hilfreich?

Lösung

Ich hatte das gleiche Problem. Ich fand eine Lösung. Es ist nicht sauber, aber es funktioniert. Knapp unterhalb der Arbeitscode.


\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}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top