I wanted to be able to have different Matlab code listings in the same document. The first three listings are from the solution found here.
How do I get rid of the thin lined boxes in the first 3 Matlab code settings, while still keeping the thin box around the last lstlisting
:
Here is the code:
\documentclass{article}
\usepackage{tcolorbox}
\usepackage{xcolor}
\tcbuselibrary{listings,skins}
\usepackage[framed,numbered,autolinebreaks,useliterate]{mcode}
\usepackage[numbered,framed]{matlab-prettifier}
\lstdefinestyle{mystyle}{
numbers=left,
numberstyle=\small,
numbersep=8pt,
language=Matlab
}
\newtcblisting{mylisting}[2][]{
arc=0pt, outer arc=0pt,
listing only,
listing style=mystyle,
title=#2,
#1
}
\begin{document}
\begin{mylisting}{}
%% Accuracy Calculation
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
\end{mylisting}
\begin{mylisting}[hbox]{}
%% Accuracy Calculation
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
\end{mylisting}
\begin{mylisting}[hbox,enhanced,drop shadow]{Accuracy Calculation}
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
\end{mylisting}
\begin{lstlisting}[
backgroundcolor=\color{blue!05},
style=Matlab-editor,
basicstyle=\ttfamily\small
]
%% Accuracy Calculation
Equal_Rows = find(diff(matrix_rec,[],2) == 0);
percent_success = (size(Equal_Rows,1)/numFolders) * 100
\end{lstlisting}
\end{document}
Best Answer
You load the
mcode
package with theframed
option, which adds the thin (undesired) frame around the code. Yourmylisting
environment is a color box from thetcolorbox
package, which adds another frame around it. This is why you have the two frames.To remove the inner frames, simply remove the
framed
option when loadingmcode
:Remark: you are using two different packages for the same purpose. If you don't watch out, you will get inconsistent output. As both these packages use
listings
in the background, they have undesired interactions: for example by removingframed
from themcode
package, suddenly the line numbers in thematlab-prettifier
listing are outside of the frame - even though you didn't change anything! Please, try to decide for one package1 and stick to that. You can setupmatlab-prettifier
to look like yourmcode
listings now, or the other way around.1
matlab-prettifier
is newer and has more features thanmcode
, and it comes with most standard LaTeX installations