Den Hintergrund der Box transparent machen

Den Hintergrund der Box transparent machen

Da ich in meinem Dokument viele mathematische Formeln in farbige Kästchen schreiben muss, möchte ich vermeiden, in jedes Kästchen ein $ zu schreiben. Gibt es eine Möglichkeit, dies newtcboxim Mathematikmodus zu definieren?

Ich habe es mit versucht \newtcbox{\mywbox}[1]{<options>}{$\displaystyle #1$}, aber es funktioniert nicht.

Dies ist mein Latex-Code:

\usepackage{tcolorbox}
\newtcbox{\mywbox}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}

\begin{document}
\obeylines

This \mywbox{$3x$} is in line math.
This $$y=\mywbox{$-5x$}-5+6$$ is not in line math.

\end{document}

Bildbeschreibung hier eingeben

Ich habe darüber \tcboxmathund \tcbhighmathim offiziellen Tcolorbox-Handbuch gelesen, verstehe aber nicht, wie ich sie einfach als neue Tcolorbox definieren kann und ob sie das sind, was ich brauche.

Antwort1

ich würde sagen

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}
\newcommand{\mywboxmath}[1]{\mywboxtext{$#1$}}

Ihr Beispiel kann werden

\documentclass{article}
\usepackage{tcolorbox}

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}
\newcommand{\mywboxmath}[1]{\mywboxtext{$#1$}}

\begin{document}

This \mywboxmath{3x} is in line math and this
\[
y=\mywboxmath{-5x}-5+6
\]
is display math.

\end{document}

Bildbeschreibung hier eingeben

Ändern Sie die Namen nach Ihren Wünschen.

Vermeiden$$ in LaTeX(und natürlich auch \obeylines).

Wenn Sie möchten, dass sich die Boxen hoch- oder tiefgestellt verhalten, ändern Sie den Code in

\documentclass{article}
\usepackage{tcolorbox}

\newtcbox{\mywboxtext}{on line,colback=white,colframe=black,size=fbox,arc=3pt,boxrule=0.8pt}

\makeatletter
\newcommand{\mywboxmath}[1]{\mathpalette\mywboxmath@do{#1}}
\newcommand{\mywboxmath@do}[2]{\mywboxtext{$\m@th#1#2$}}
\makeatother

\begin{document}

This $\mywboxmath{3x}$ is in line math and this
\[
y_{\mywboxmath{0}}=\mywboxmath{-5x}-5+6
\]
is display math.

\end{document}

Beachten Sie, dass Sie sich in diesem Fall \mywboxmathim Mathematikmodus befinden müssen.

Antwort2

\tcboxmathSie können hierfür die theoremsfolgende Bibliothek verwenden tcolorbox:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\newcommand*{\mywbox}{%
  \tcboxmath[colback=white, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt]%
}

\begin{document}

This \mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

Bildschirmfoto

Möglicherweise möchten Sie die Dinge mithilfe eines Stils auch ein wenig abstrahieren, sodass Sie ihn bei Bedarf auf andere Felder anwenden können:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\tcbset{my math box/.style={
          colback=white, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt}
}

\newcommand*{\mywbox}{\tcboxmath[my math box]}

\begin{document}

This \mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

Den Hintergrund der Box transparent machen

Dies kann mit /tcb/opacitybackund einem Skin mit einemPuzzleRahmen-Engine, wie standard jigsawoder enhanced jigsaw.

\documentclass[fleqn]{article}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\tcbset{
  my math box/.style={
    standard jigsaw,   % useful for 'opacityback' and 'opacityframe'
    colback=green!20, colframe=black, size=fbox, arc=3pt, boxrule=0.8pt,
    opacityback=0.6,
  }
}

\newcommand*{\mywbox}{\tcboxmath[my math box]}

\begin{document}

This \makebox[0pt]{%
  \raisebox{-0.5\height}[0pt][0pt]{\hspace{1cm}\includegraphics{example-image-duck}}%
  }%
\mywbox{3x} is in line math.
This
\[ y = \mywbox{-5x} - 5 + 6 \]
is not in line math.

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen