So, I am writing a report with Prolog code listings in it. I have been using lstlisting to make my listings and I made my code centered on the page, such as this:
\renewcommand{\figurename}{Listing}
\begin{figure}[thp]
\centering
\begin{tabular}{c}
\begin{lstlisting}[language=Prolog]
somePredicate(A, B) :-
arbitraryPredicate(A),
anotherPredicate(B).
\end{lstlisting}
\end{tabular}
\caption{My Prolog Predicate}
\label{lst:firstListing}
\end{figure}
Generated output:
It works very well. This is based on the following answer on stackexchange: https://tex.stackexchange.com/a/5822/46424
However, I want to switch to the minted-package to represent my code snippets, as it shows the code with nice colors. This is where it goes wrong. I got minted to work, but I cannot get my listing centered anymore.
After searching on the web I found only one question about aligning minted code: LaTeX align minted code fragments
So, just as it shows there in the answers of that question, I tried to use a minipage. This, however, did not work as expected. The code is simply aligned left instead of centered if I write the following:
\renewcommand{\figurename}{Listing}
\begin{figure}[thp]
\begin{minipage}[t]{\textwidth}
\centering
\begin{minted}{prolog}
somePredicate(A, B) :-
arbitraryPredicate(A),
anotherPredicate(B).
\end{minted}
\caption{My Prolog Predicate}
\label{lst:firstListing}
\end{minipage}
\end{figure}
Generated output:
I have also tried to combine tabular with minted, but then pdflatex gets an error and no pdf-file gets generated.
So, my question is: how do I make my code listings, that are represented by the minted-package, centered on my page?
Thanks in advance!
minted
? There may be a way of configuringlistings
to get the highlighting you want. Try, for instance,\lstdefinestyle{myPrologstyle} { language=Prolog, basicstyle = \ttfamily\color{blue}, moredelim = [s][\color{black}]{(}{)}, literate = {:-}{{\textcolor{black}{:-}}}2 {,}{{\textcolor{black}{,}}}1 {.}{{\textcolor{black}{.}}}1 }
. I encourage you to post another question about how to customiselistings
to mimic the Pygments's Prolog lexer (used internally byminted
).