2

I'm writing an article in LaTex about programming and I need to write the signature of a C++ method using a specific format, only the statement of the method, not the body.

for example:

void cvtColor( InputArray src, OutputArray dst, int code, int dstCn=0 );

I would like something like this:

void cvtColor( InputArray src, 
               OutputArray dst, 
               int code, 
               int dstCn=0 
              );

Thanks.

  • This might be possible, but perhaps the doxygen way is better to achieve this. Welcome to TeX.SX anyway – user31729 May 18 '15 at 15:59
  • verbatim is perhaps what you need ... – juanuni May 18 '15 at 16:05
  • Maybe you can achieve that using the listings package. – Aradnix May 18 '15 at 16:09
  • Thank you very much, we can do this with the three options, they are real solutions, but I finally used listings – jperezmartin May 18 '15 at 16:41
0

You can do this in a number of ways. Here are some options:

  • verbatim

    enter image description here

    \documentclass{article}
    
    \usepackage{lipsum}
    
    \begin{document}
    
    \lipsum*[1]
    \begin{verbatim}
    void cvtColor( InputArray src, 
                   OutputArray dst, 
                   int code, 
                   int dstCn=0 
                  );
    \end{verbatim}
    
    \lipsum[2]
    
    \end{document}
    
  • fancyvrb; more flexibility than a regular verbatim environment.

    enter image description here

    \documentclass{article}
    
    \usepackage{fancyvrb,lipsum}
    
    \begin{document}
    
    \lipsum*[1]
    \begin{Verbatim}
    void cvtColor( InputArray src, 
                   OutputArray dst, 
                   int code, 
                   int dstCn=0 
                  );
    \end{Verbatim}
    
    \lipsum[2]
    
    \end{document}
    
  • listings; more flexibility with formatting based on language.

    enter image description here

    \documentclass{article}
    
    \usepackage{listings,lipsum}
    
    \lstset{
      language = C++,
      basicstyle = \ttfamily
    }
    
    \begin{document}
    
    \lipsum*[1]
    \begin{lstlisting}
    void cvtColor( InputArray src, 
                   OutputArray dst, 
                   int code, 
                   int dstCn=0 
                  );
    \end{lstlisting}
    
    \lipsum[2]
    
    \end{document}
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.