I'm using the minted package to produce nice looking java-code but I would like to make a box around the code so it is easier to separate the code from the rest of the document.
What is the easiest way to do this?
Here is an example of my document. I'd like the java-code to be inside a box.
:
Thanks for the suggestions. Torbjørn T's solution seems to work perfect but some of my code is too wide for the normal width defined by the margins. The minted environment is ignoring the margins (I can't really decide wether or not this is a bad thing) but the frame produced by minted follows the margin-rule.
Would it be best to make the frame ignore the margins or make my code fit into the box (which probably will look pretty stupid with those lines consisting of a few words)?
Best Answer
As mentioned by Torbjørn T.
minted
has some options to add a frame. Howeverminted
doesn't do the frame. This is done by the packagefancyvrb
. The possibilities of frames withfancyvrb
are limited. If you want e.g. round corners you can use another package liketcolorbox
ormdframed
.The example below shows you the usage of
tcolorbox
. I am using the advantages ofetoolbox
to add a frame around everyminted
environment.EDIT: If you want to have automatic line breaks with
fancyvrb
you can use the following. Please note line breaks only occur at spaces. A line break has pre hook in form of$\rightarrow$
. You can change it, of course. To get the symbol in front of a line I usedlineno
.