1

I'm trying to add MATLAB code to a beamer presentation, but using matlab-prettifier package numbering isn't showing. Does anybody knows why this is happening?

I'm not even sure that using matlab-prettifier is the best option, but I wasn't able to use matlab-prettifier or anything else. If someone has a better option to add MATLAB code on a beamer presentation, please tell me.

This is what I wrote:


\documentclass{beamer}
\usetheme{Boadilla}
\title{Titolo Presentazione}
\subtitle{Sottotitolo Presentazione}
\author{Author}
\institute{Università di Pisa}
\date{\today}

\usepackage{listings}
\usepackage[framed,numbered]{matlab-prettifier}

\begin{document}

\begin{frame}[fragile]
\frametitle{MATLAB code}
{\fontencoding{T1}\selectfont
\begin{lstlisting}[
    style=Matlab-editor,
    basicstyle=\mlttfamily,
  ]
% create a file for output
!touch testFile.txt
fid = fopen('testFile.text', 'w')
for i=1:10
  fprintf(fid,'%6.2f \n', i);
end
\end{lstlisting}
}
\end{frame}

\end{document}

1 Answer 1

1

Not a complete answer, but to help you quickly:

The numbers are there, but they leaked from the page. Try to compile using an adjustbox and you see them on the left.

\documentclass{beamer}
\usetheme{Boadilla}
\title{Titolo Presentazione}
\subtitle{Sottotitolo Presentazione}
\author{Author}
\institute{Università di Pisa}
\date{\today}

\usepackage{listings}
\usepackage[framed,numbered]{matlab-prettifier}
\usepackage{adjustbox} % <------------ added

\begin{document}

\begin{frame}[fragile]
    \frametitle{MATLAB code}
    \adjustbox{width=7cm,keepaspectratio}{ % <------------ added
        {\fontencoding{T1}\selectfont
        \begin{lstlisting}[
            style=Matlab-editor,
            basicstyle=\mlttfamily,
          ]
        % create a file for output
        !touch testFile.txt
        fid = fopen('testFile.text', 'w')
        for i=1:10
          fprintf(fid,'%6.2f \n', i);
        end
        \end{lstlisting}
        }
    } % <------------ added

\end{frame}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .