I've created (copied) a simple environment in order to create a frame around a piece of text. The environment uses the mdframes environment in order to box the content and a simple macro changemargin that is used to add some white space at the left and at the right of the box.


% mdframe: put a certain amount of text in a box

% macro to change margins

% custom environment
    \begin{mdframed}[style=exampledefault, frametitle={#1}]

\usepackage{lipsum} % add some text

    \begin{Boxed}{I'm the title}
        I'm the content. I've a nice frame around me.

This is the result. It works perfectly. enter image description here

My question is, can I use my environment like a command?

  • @ChristianHupfer ok thank you. I'm adding it
    – incud
    Jan 29 '17 at 10:39
  • I am correcting my previous statement (and deleted it) -- it is possible
    – user31729
    Jan 29 '17 at 10:41
  • thank you very much :) I'm trying it. Is the question ok?
    – incud
    Jan 29 '17 at 10:49
  • Yes, much better, but do you really need the changemargin 'environment'?
    – user31729
    Jan 29 '17 at 10:50
  • Probably no. Without it the result is much nicer
    – incud
    Jan 29 '17 at 10:54

It is in fact possible to use a mdframed environment within a command if it is wrapped in an internal BoxedInternal environment.

I've improved the example with an optional argument to the BoxedInternal environment and \Boxed macro.

The question is whether such wrapper commands are useful in general.





    \begin{mdframed}[style=exampledefault, frametitle={#2},#1]





enter image description here

  • It works perfectly
    – incud
    Jan 29 '17 at 10:55
  • @Ignus: Happy TeXing then. And tcolorbox has such \Boxed commands out of the box (pun intended ;-), perhaps you can give it a try also
    – user31729
    Jan 29 '17 at 10:56
  • Can I ask you another thing? Why Boxed takes three arguments insted of two?
    – incud
    Jan 29 '17 at 10:59
  • @Ignus: You can use it this way \Boxed[backgroundcolor=green]{Title}{Content}, the first argument with [...] is handed to the mdframed environment, so you could change the view etc. of the underlying box. If you never need this feature, just don't think about [...], just always use it as \Boxed[title]{content} and all is fine
    – user31729
    Jan 29 '17 at 11:06

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.