1

I have the following settings for the listing package and need to print program outcomes in the same manner, but with its own numbering and removing "Listing" in a caption), i.e., "Outcomes for Listing 1." Also, I need to turn on or turn off numbers depending on the task.

% !TeX program = xelatex
\documentclass[fontsize=11pt,paper=a5, pagesize=auto]{extbook}
\usepackage[a5paper]{geometry}
\usepackage[colorlinks=true, allcolors=black]{hyperref}
\usepackage{blindtext}
\usepackage{amsmath} % for math equations
\usepackage{amssymb}
\usepackage{fontspec}
\usepackage{polyglossia}
%% set main font
\setdefaultlanguage{english}
\setmainfont[Ligatures=TeX]{Liberation Serif}
%% set mono font
\setmonofont[Scale=MatchLowercase]{Noto Mono}
%% set the look of algorithms
%% https://tex.stackexchange.com/questions/381104/algorithm2e-why-are-some-of-my-texts-are-italicized-and-some-are-not
\usepackage[scaled, semibold]{sourcecodepro}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}
% ,algochapter
\usepackage{xcolor,xcolor-material}
\newcommand{\mykwsty}[1]{\textcolor{black}{\textbf{\texttt{#1}}}}
\SetKwSty{mykwsty}
\setlength{\algomargin}{1.5em}
\SetAlFnt{\small\ttfamily} 
\SetAlCapFnt{\normalfont\bfseries\hspace*{-0.35em}}
\SetNlSty{ttfamily}{\color{black}\scriptsize\bfseries}{}
%% https://tex.stackexchange.com/questions/653074/algorithm2e-make-the-topmost-and-bottom-horizontal-lines-thicker
\setlength\algoheightrule{0.5pt}        % The upper and the lower rules
\setlength\algotitleheightrule{0.5pt} % The rule between a title and code
%% set the look of listings 
%% https://tex.stackexchange.com/questions/73392/how-to-make-lstlisting-look-exactly-like-the-algorithm-environment
\usepackage{listings}
\usepackage{caption}
\lstset{
basicstyle=\small\ttfamily,
numbers=left,
numbersep=5pt,
numberstyle=\bf\color{black}\scriptsize\ttfamily,
frame=tb,
framexleftmargin=1.7em,
xleftmargin=\algomargin,
}
\renewcommand*\thelstnumber{\arabic{lstnumber}}
\DeclareCaptionFormat{mylst}{\hrule#1#2#3}
\captionsetup[lstlisting]{format=mylst,labelfont=bf,singlelinecheck=off,labelsep=colon}
% \renewcommand{\lstlistingname}{\ \ \ Listing}

%% start document

\begin{document} % Algorithm using algorithm2e package { \begin{algorithm}[H] \DontPrintSemicolon \SetKwFunction{FMain}{factorial} \SetKwProg{Fn}{Function}{\string:}{} \Fn{\FMain{$n$}}{ \KwIn{an integer $n$} \KwOut{the factorial of $n$} \If{$n \leq 1$}{ \Return $1$; } \Return $n \times \FMain{n-1}$; } \caption{Recursive factorial function} \end{algorithm} }

\begin{lstlisting}[caption={Search for SLAE solution.},language=Octave, label=lst:7.1]

Example 1.1 Solution SLAE using backslash ()

display(Matrix of coefficients) A = [2 -3 1; 2 1 -4; 6 -5 2] display(Free Members Column) b = [2; 9; 17] display(Solution x = A\b) x = A \b display(Check norm(Ax-b)) norm(A x - b) display(Validation) b - A * x \end{lstlisting}

\begin{lstlisting}[caption={Outcomes for the listing \ref{lst:7.1}}, nolol=true] Matrix of coefficients A = 2 -3 1 2 1 -4 6 -5 2 Free Members Column b = 2 9 17 Solution x = A b x = 5.00000 3.00000 1.00000 Check norm(A*x-b) ans = 1.8310e-15 Check ans = 4.4409e-16 -1.7764e-15 0.0000e+00 \end{lstlisting}

\listofalgorithms \lstlistoflistings \end{document}

Desired outcome view

Thruston
  • 42,268
vua72
  • 11

0 Answers0