如何在 mdframed 的選項中明確將顏色設為透明/無?

如何在 mdframed 的選項中明確將顏色設為透明/無?

是否可以backgroundcolormdframed包中明確設定選項,以便背景保持透明(或者,我們說“空”)?

它可能是

\begin{mdframed}[backgrouncolor = ***]
Test
\end{mdframed}

***= no color, empty{}但這些都不起作用。

是否可以在 mdframed 的選項中明確將顏色設為透明/無?


編輯

更明確地說,是否存在一個值***使得

\begin{mdframed}[backgrouncolor = ***]
Test
\end{mdframed}

% assuming no global options have been set
\begin{mdframed}
Test
\end{mdframed}

是等價的?

答案1

我不確定我是否理解這個問題,所以我提出三個可能的答案:

第一個選項:

您可以使用\mdfsetup定義全域設定:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}

\mdfsetup{backgroundcolor=red!20}

\begin{document}

\begin{mdframed}
test
\end{mdframed}

\end{document}

在此輸入影像描述

第二個選項:

預設情況下,在初始配置中,mdframed將背景顏色設為white,因此

\begin{mdframed}[backgroundcolor=white]
test
\end{mdframed}

\begin{mdframed}
test
\end{mdframed}

是等價的;請注意,預設背景顏色並不是真正透明的,它是白色的,並且沒有預先定義的鍵來設定背景顏色的不透明度(有關透明度問題的解決方案,請tcolorbox參閱下面的第三個選項)。

一個例子:

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}

\begin{document}

\begin{mdframed}[backgroundcolor=white]
test
\end{mdframed}

\begin{mdframed}
test
\end{mdframed}

\end{document}

在此輸入影像描述

是等價的。

第三個選項:

我不記得mdframed提供了設置背景不透明度的方法(但我可能是錯的)。和tcolorboxopacityframe=<value>您可以使用, opacityback=<value>0表示完全透明,1表示不透明)控制背景和/或框架不透明度;一個小範例(\pagecolor{cyan!10}僅用於使 opcity 效果可見):

\documentclass{article}
\usepackage{tcolorbox}

\pagecolor{cyan!10}
\begin{document}

\begin{tcolorbox}[
  standard jigsaw,
  opacityframe=0.5,
  opacityback=0.2
]
test
\end{tcolorbox}

\end{document}

在此輸入影像描述

答案2

簡單且「非法」的解決方案

你必須使用backgroundcolor = none.這是一個“非法解決方案”,因為none不退出。那麼,backgroundcolor = none就等同於backgroundcolor = frogs...

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}

\begin{document}
\pagecolor{yellow}
\begin{mdframed}[backgroundcolor = none]
Test
\end{mdframed}
\end{document}

在此輸入影像描述

複雜且「合法」的解決方案

\documentclass{article}
\usepackage[framemethod=tikz]{mdframed}

\begin{document}
\pagecolor{yellow}
\begin{mdframed}[apptotikzsetting={%
    \tikzset{mdfbackground/.append style={fill=red,fill opacity=0}}}]
Test
\end{mdframed}

\end{document}

在此輸入影像描述

相關內容