I am going to include some scripts (programming) in my document and I used \texttt
to make them look different from the rest of the document and I am gonna move them to the center of page with center
environment but I don't have any clue how to align them (like the alignment used for equations):
\begin{center}
\texttt{kmeans=: 3 :0 \\
Nr=: \$,smp \\
dis=: \%: @ +/"1(initial -"1/ grid)\^ 2 \\
index=:(|:dis) i."1 (,.<./"1 (|:dis)) \\
}
\end{center}
Best Answer
If you're not interested in a specific formatting of the scripts, then you can use the
fancyvrb
package to adjust the code location. Here's an example that indents the entire code by2\parindent
(twice the standard\parindent
) for a consistent horizontal alignment across scripts:Using something like a
verbatim
environment (orVerbatim
as provided byfancyvrb
) removes the need to escape characters that are otherwise treated differently inside regular text. Moreover, the default font used it\ttfamily
(this can be changed).For actually centering the content,
fancyvrb
also allows you to capture the content in a box which provides the means to move it around:For formatting options, you should consider using the
listings
package.