Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 9 down vote accepted

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

share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.