3

I want to put SOURCE in the algorithm as I put them ?, I want to use this \usepackage{copyrightbox}

\documentclass{book}

\usepackage{lipsum}
\usepackage{listings}
\usepackage{tocloft}
\renewcommand{\lstlistingname}{Algoritmo}% Listing -> Algorithm
\renewcommand{\lstlistlistingname}{Indice de \lstlistingname s}% List of Listings -> List of Algorithms

\begin{document}


\chapter{A chapter}
\section{First section}
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
x=a+b
};
\end{lstlisting}
[lipsum]
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
x=a+b
};
\end{lstlisting}

\chapter{second chapter}
\section{First section}
\medskip
\begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
x=a+b
};
\end{lstlisting}
\end{document}
  • ...we need more detail. Where do you want it? – Werner Nov 26 '18 at 6:34
  • 1
    lstlisting as well verbatim doesn't work inside macros (as the copyrightbox is. you can emulate it functions with: {\small source: unknown \dots\par\medskip} immediately after \end{lstlisting} – Zarko Nov 26 '18 at 6:34
  • @Zarko then how could I simulate and what remains the same as in the pictures and tables? – x-rw Nov 26 '18 at 13:31
  • @x-rw, as i told you in comment. result should be very similar. – Zarko Nov 26 '18 at 18:47
  • @Zarko I'm new to latex please, i need a example – x-rw Nov 26 '18 at 18:49
3

let me extend my comment to an answer ...

  • lstlisting as well verbatim doesn't work inside macros (what the copyrightbox is).

  • you can emulate its functions with:

    {\small source: unknown \dots\par\medskip} 
    

    which you insert immediately after \end{lstlisting}

  • another possibilities is to define new command in preamble, for example

    \newcommand\source[1]{\hfill\parbox{\dimexpr\linewidth-3em}{
                            \vspace*{-1ex}\noindent\small
                            source: #1
                            \par\medskip}
                            }
    

    and than use as before.

  • both cases you can see in mwe below:

    \documentclass{book}
    
    \usepackage{lipsum}
    \usepackage{listings}
    \renewcommand{\lstlistingname}{Algoritmo}% Listing -> Algorithm
    \renewcommand{\lstlistlistingname}{Indice de \lstlistingname s}% List of Listings and  Algorithms
    
    \newcommand\source[1]{\hfill\parbox{\dimexpr\linewidth-3em}{
                            \vspace*{-1ex}\noindent\small
                            source: #1
                            \par\medskip}
                            }
    \begin{document}
        \chapter{A chapter}
    \section{First section}
    \lipsum[11]
    \medskip
    \begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
    x=a+b
    };
    \end{lstlisting}
        {\small source: unknown \dots\par\medskip}  % <--- defined "in-line"
    \lipsum[11]
    \medskip
    \begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
    x=a+b
    };
    \end{lstlisting}
        \source{unknown \dots}  % <--- used newcommand defined in preamble
    
        \chapter{second chapter}
    \section{First section}
    \medskip
    \begin{lstlisting}[language=Java,escapechar=|,caption= Algoritmo  hiperparametros]
    x=a+b
    };
    \end{lstlisting}
    \end{document}
    

enter image description here

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.