1

I'm trying to make a floating "Tip" box. This is my MWE:

\documentclass{report}
\usepackage{wrapfig}
\usepackage{framed}
\usepackage{lipsum}

\newenvironment{tip}[1][3cm]
    {\begin{wrapfigure}{R}{#1}\begin{framed}Tip:\\}
    {\end{framed}\end{wrapfigure}}

\begin{document}

\begin{tip}
Hello this is a test
\end{tip}
\lipsum[1]
\end{document}

Right now it looks like this: output

And this is what I want:

wanted

4

Define a \newcommand instead of a \newenvironment

\documentclass{report}
\usepackage{wrapfig}
\usepackage{framed}
\usepackage{lipsum}

    \newcommand{\tip}[2][3cm]
        {\begin{wrapfigure}{R}{#1}
        \begin{framed}
        Tip:\\ #2
        \end{framed}
        \end{wrapfigure}
        }

    \begin{document}
    \tip {Hello this is a test}
    \lipsum[1]
    \tip[5cm]{Hello this a wider box}
    \lipsum[2]
    \end{document}

enter image description here

  • i cant reproduce your result. first \tip command is correct placed, but it overwrite paragraph text. the second one is below of text. i use recent miktex – Zarko Jan 3 at 12:21
  • @Zarko I have rechecked the code and its output first on overleaf and second with Texlive 2018. For me it's ok! – Hafid Boukhoulda Jan 3 at 12:32
  • than i can only concluded that within mitex is something different as in texlive or in `overleaf`` ... – Zarko Jan 3 at 13:12
  • @zarko I realy don't know what to conclude! I don't use miketex. – Hafid Boukhoulda Jan 3 at 13:19
  • 1
    The reason why a command works and an environment not is that the wrapfigure must not be included into a group, which is added by the environment. This is stated in the manual. Hafids solution works for me with TeXLive 2018. I don't think MikTeX will act any different. The underlying TeX engine is the same! – Martin Scharrer Jan 4 at 8:35

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.