11

What I wish to achieve is rectangle around code, with code in the font format as shown. How should I achieve this format?

Code Fragment example code

11

Here are some methods (including the listing package already shown by percusse):

\documentclass[journal,a4paper]{IEEEtran}
\usepackage{listings}
\usepackage{fancyvrb}
\usepackage{framed}
\usepackage[listings,skins]{tcolorbox}
\usepackage[skipbelow=\topskip,skipabove=\topskip]{mdframed}
\mdfsetup{roundcorner=0}

\begin{document}
\title{How to insert framed code}
\author{Me}
\maketitle
% The Abstract
\begin{abstract}
The article shows some methods to framed code.
\end{abstract}

% The Keywords 
\begin{IEEEkeywords}
Code, framed, boxes.
\end{IEEEkeywords}

\section{Framed code}

\subsection{Using listings}

\begin{lstlisting}[frame=single]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}

\subsection{Using fancyvrb}

\begin{Verbatim}[frame=single]
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{Verbatim}

\subsection{Using framed+verbatim}

\begin{framed}
\begin{verbatim}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{verbatim}
\end{framed}

\subsection{Using tcolorbox}
% setting for a simple frame
\tcbset{lowerbox=ignored,skin=freelance,frame code={
    \draw (frame.south west)rectangle(frame.north east);

  }
}

\begin{tcblisting}{}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{tcblisting}

\subsection{Using mdframed+listings}

\begin{mdframed}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
\end{lstlisting}
\end{mdframed}


\end{document}

enter image description here

8

You can use the listings package and adjust it according to your needs.

\documentclass{ieeetran}
\usepackage{listings}
\usepackage{lipsum} %<- For dummy text

\title{The title}
\author{The author}
\begin{document}
\maketitle
\begin{abstract}
\lipsum[1]
\end{abstract}
\lipsum[1-4]

\begin{lstlisting}[frame=single,basicstyle=\ttfamily]
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\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.