Consider this MWE


\NewDocumentCommand\MySmallFigure{o m m m m}{%

  auto counter,
  blend into=listings
  label = #2,
  listing and text,

% This works
{An image ....}%

% This doesn’t, since its a figure environment inside a tcolorbox.
{An image ....}%

I want to show the usage of the command \MySmallFigure and then the result of the command within a tcolorbox/tcblisting.

But ...

./tcbfigure.listing:1: LaTeX Error: Not in outer par mode.

... I am missing something, obviously.

  • 3
    just remove the figure environment. The purpose of figure is to take its content out of the document flow and allow it to float, but you don't want the image to float out of the box here. – David Carlisle Sep 6 '18 at 12:40
  • The only other use of figure is to use \caption, which can be replaced by \captionof{figure}{...} (caption package). – John Kormylo Sep 6 '18 at 12:41
  • ok, but then I cannot show the code \begin{figure}... what I want to do. In fact the figure environment is part of a (rather larger) \newcommand , which I shortend to the core. So I think it is important (for my purpose) to show the whole content of the \newcommand. – LukasCB Sep 6 '18 at 12:43
  • 1
    feel free to edit the question to clarify it (but the core of the answer has to be the same, you can not have a float inside any kind of box) But if you clarify the example to be closer to your use case, someone will suggest how to fix it. – David Carlisle Sep 6 '18 at 12:45
  • 1
    I know it feels wrong to fake these outputs, but for me there simply was a point where the code-as-displayed was not actually the code-as-executed in the lower part of the box and so I couldn't really think of a better way to solve this. While I think it is important to have good documentation I allow myself more leeway in the code I write for the documentation than for the actual package code. Compromises and quick and dirty fixes just seem more acceptable there. – moewe Sep 6 '18 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.