ボックスの背景を透明にする

ボックスの背景を透明にする

私の文書では色付きのボックスに多くの数式を記述する必要があるため、各ボックス内に $ を記述するのは避けたいです。newtcbox数式モードで定義する方法はありますか?

試してみました\newtcbox{\mywbox}[1]{<options>}{$\displaystyle #1$}が、うまくいきませんでした。

これは私の LaTeX コードです:

\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}

ここに画像の説明を入力してください

\tcboxmath公式の tcolorbox マニュアルでとについて読みました\tcbhighmathが、これらを単に newtcbox として定義する方法と、これらが必要なものかどうかがわかりません。

答え1

私はこう言います

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

あなたの例は

\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}

ここに画像の説明を入力してください

お好みに合わせて名前を変更してください。

$$LaTeXでは避ける(そしてもちろん も\obeylines)。

ボックスを下付き文字または上付き文字として動作させる必要がある場合は、コードを次のように変更します。

\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}

この場合、 が\mywboxmath数式モードになっている必要があることに注意してください。

答え2

これは、次のライブラリ\tcboxmathを使用して実行できます。theoremstcolorbox

\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}

スクリーンショット

必要に応じて他のボックスに適用できるように、スタイルを使用して少し抽象化することもできます。

\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}

ボックスの背景を透明にする

/tcb/opacitybackこれは、スキンを使用して行うことができますジグソーパズルstandard jigsawまたはなどのフレーム エンジン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}

ここに画像の説明を入力してください

関連情報