[Tex/LaTex] Center a Listing on page

horizontal alignmentlistings

I am trying to center a listing horizontally within a page.

So far I have tried defining the following macro:

    {\centering \lstset{float=htpb,#1}} 

But it did not work.

I have read this question and answer, but I would prefer a solution that does not rely in figures or tables.

Best Answer

only possible when you define a width for a minipage: