1

The following code fails with the error

! LaTeX Error: Command \mybox already defined.
               Or name \end... illegal, see p.192 of the manual.



 \usepackage[most]{tcolorbox}

\newtcolorbox{mybox}[2][]{%
    colback=bg,
    colframe=blue!75!black,
    fonttitle=\bfseries,
    coltitle=blue!75!black,
    colbacktitle=bg,
    enhanced,
    attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
  title=#2,
  #1}

%--------------------

\usepackage{fancybox} %pour faire l'encadrement
\newcommand{\mybox}[1]{
\setlength{\fboxsep}{7pt}
\begin{center}
\shadowbox{#1}
\end{center}}

%--------------------

Could you please help me

  • 1
    You can have both a tcolorbox mybox and a command \mybox. Choose another name. – Ulrike Fischer Dec 15 '17 at 11:41
  • Please help me because I'm beginer – Student Dec 15 '17 at 11:43
  • 5
    you just need to call it something else so change \newcommand{\mybox}[1]{ to \newcommand{\anythingbutnotmybox}[1]{ – David Carlisle Dec 15 '17 at 11:46
  • 1
    Sorry I meant "you can't" not "you can". – Ulrike Fischer Dec 15 '17 at 11:55
  • 2
    In case you weren't aware, and you are confused why \mybox is already defined: When you write \begin{mybox} LaTeX translates that into \mybox with some checking around it. Therefore, when you created the environment mybox as a new tcolorbox, internally, that defined the command \mybox :) – Alex Recuenco Dec 15 '17 at 12:42
3

You just replace \mybox by for example \cadre us follows:

    \usepackage[most]{tcolorbox}

    \newtcolorbox{mybox}[2][]{%
    colback=bg,
    colframe=blue!75!black,
    fonttitle=\bfseries,
    coltitle=blue!75!black,
    colbacktitle=bg,
    enhanced,
    attach boxed title to top left={yshift=-1.2mm, xshift=2mm},
  title=#2,
  #1}

%--------------------

\usepackage{fancybox} %pour faire l'encadrement
\newcommand{\cadre}[1]{
\setlength{\fboxsep}{7pt}
\begin{center}
\shadowbox{#1}
\end{center}}

%--------------------

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.