由于“混合模式=正片叠底”,图中的白色会改变颜色

由于“混合模式=正片叠底”,图中的白色会改变颜色

我使用了以下方法广告 Tikz 填充矩形,用作原始文档中块文本的背景,非常感谢@marmot,在这里可以使用渐变颜色和圆角。

但是,当我在其中添加带有白色的图形时,由于 ,白色将被颜色框替换blend mode = multiply。我怎样才能使其保持白色而不是任何原始颜色?

一个例子: 在此处输入图片描述

代码如下

\documentclass{article}
\usepackage{tikz}
\usepackage{refcount}
\usetikzlibrary{backgrounds,calc}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\tikzset{SimpleBox/.style={draw,red,thick,fill=blue,fill opacity=0.3,rounded
corners}}
\usepackage{float}



\newcounter{tmp}

\newcommand{\StartBox}[1][]{%
  \stepcounter{tmp}%from https://tex.stackexchange.com/a/52579/121799
  \tikz[remember picture,overlay, baseline=(Begin.base)]{%
  \node[anchor=base,inner sep=0pt,outer sep=0pt] (Begin) {\strut};}
  \label{a\thetmp}%
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp} \else
  \begin{tikzpicture}[overlay, remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
   \draw[SimpleBox,#1] ($(current page text area.south-|WestLine)-(0,2pt)$)
   --      (Begin.north-|WestLine) -- (Begin.north-|EastLine) 
   --  ($(current page text area.south-|EastLine)-(0,2pt)$);
   \end{scope}
  \end{tikzpicture}%
  \fi%
}

\newcommand{\EndBox}[1][]{%
\tikz[remember picture,overlay, baseline=(End.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (End) {\strut};}%
  \label{b\thetmp}
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp}
  \begin{tikzpicture}[overlay,remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
    \draw[SimpleBox,#1] (Begin.north-|WestLine) rectangle (End.south-|EastLine);
   \end{scope}
  \end{tikzpicture}
  \else
  \begin{tikzpicture}[overlay,remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
   \draw[SimpleBox,#1] ($(current page text area.north-|WestLine)+(0,2pt)$)
   --      (End.south-|WestLine) -- (End.south-|EastLine) 
   --  ($(current page text area.north-|EastLine)-(0,2pt)$);
   \end{scope}
  \end{tikzpicture}
  \fi
}

\newcommand{\SimpleBox}[2][]{%
\StartBox[#1]%
#2\EndBox[#1]}


\begin{document}
    My original picture outside the box:
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.1]{tex_exchange.png}
    \end{figure}

\SimpleBox{My original picture inside the box:
\begin{figure}[H]
    \centering
    \includegraphics[scale=0.1]{tex_exchange.png}
\end{figure}}

\SimpleBox{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at. Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.}

\lipsum[2]

\tikzset{SimpleBox/.style={draw,blue,thick,fill=red,fill opacity=0.3}}

\SimpleBox{\lipsum[3]}

\lipsum[4]


\SimpleBox[draw=yellow,fill=yellow]{Wanna yellow?}


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem.

\SimpleBox{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at. Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.}
\end{document}

答案1

好的,如果你真的想这么做,你可以使用

\documentclass{article}
\usepackage{eso-pic}
\usepackage{tikz}
\usepackage{refcount}
\usetikzlibrary{backgrounds,calc}
\usepackage{tikzpagenodes}
\usepackage{lipsum}
\tikzset{SimpleBox/.style={draw,red,thick,fill=blue,fill opacity=0.3,rounded
corners}}
\usepackage{float}



\newcounter{tmp}

\newcommand{\StartBox}[1][]{%
  \stepcounter{tmp}%from https://tex.stackexchange.com/a/52579/121799
  \tikz[remember picture,overlay, baseline=(Begin.base)]{%
  \node[anchor=base,inner sep=0pt,outer sep=0pt] (Begin) {\strut};}
  \label{a\thetmp}%
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp} \else
  \begin{tikzpicture}[overlay, remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
   \draw[SimpleBox,#1] ($(current page text area.south-|WestLine)-(0,2pt)$)
   --      (Begin.north-|WestLine) -- (Begin.north-|EastLine) 
   --  ($(current page text area.south-|EastLine)-(0,2pt)$);
   \end{scope}
  \end{tikzpicture}%
  \fi%
}

\newcommand{\EndBox}[1][]{%
\tikz[remember picture,overlay, baseline=(End.base)]{%
\node[anchor=base,inner sep=0pt,outer sep=0pt] (End) {\strut};}%
  \label{b\thetmp}
  \ifnum\getpagerefnumber{a\thetmp}=\getpagerefnumber{b\thetmp}
  \begin{tikzpicture}[overlay,remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
    \draw[SimpleBox,#1] (Begin.north-|WestLine) rectangle (End.south-|EastLine);
   \end{scope}
  \end{tikzpicture}
  \else
  \begin{tikzpicture}[overlay,remember picture]
   \path (current page text area.north west) -- (current page text area.south west)
    node(WestLine)[left]{};
   \path (current page text area.north east) -- (current page text area.south east)
    node(EastLine)[right]{};
   \begin{scope}[on background layer,blend mode=multiply]
   \draw[SimpleBox,#1] ($(current page text area.north-|WestLine)+(0,2pt)$)
   --      (End.south-|WestLine) -- (End.south-|EastLine) 
   --  ($(current page text area.north-|EastLine)-(0,2pt)$);
   \end{scope}
  \end{tikzpicture}
  \fi
}

\newcommand{\SimpleBox}[2][]{%
\StartBox[#1]%
#2\EndBox[#1]}


\begin{document}
    My original picture outside the box:
    \begin{figure}[H]
        \centering
        \includegraphics[scale=0.1]{tex_exchange.png}
    \end{figure}

\SimpleBox{My original picture inside the box:
\begin{figure}[H]
    \centering
    \tikz[remember
    picture]{\node(pic){\includegraphics[scale=0.1]{tex_exchange.png};}}
    \AddToShipoutPictureFG*{\tikz[remember picture,overlay]{\node at (pic)
    {\includegraphics[scale=0.1]{tex_exchange.png}};}} 
\end{figure}}

\SimpleBox{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at. Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.}

\lipsum[2]

\tikzset{SimpleBox/.style={draw,blue,thick,fill=red,fill opacity=0.3}}

\SimpleBox{\lipsum[3]}

\lipsum[4]


\SimpleBox[draw=yellow,fill=yellow]{Wanna yellow?}


Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem.

\SimpleBox{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed a leo ut
erat luctus scelerisque. Suspendisse auctor mauris sit amet fringilla
hendrerit. Maecenas eu tortor eu diam fringilla scelerisque sit amet eget enim.
Nam vitae bibendum erat, sit amet scelerisque felis. Suspendisse placerat
vitae velit pharetra lobortis et marmottae. Donec ut erat a erat porta aliquet. Nulla eget
augue sem. Proin orci neque, eleifend id eleifend id, venenatis sit amet diam.
Mauris lacus est, cursus eget sapien at, pharetra lobortis ante. Proin
tempus ipsum tellus, ut ultricies magna congue nec. Vestibulum ante ipsum primis
in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse potenti.
In posuere dapibus urna, vitae euismod magna iaculis at. Pellentesque pretium,
lorem ut vehicula egestas, velit dolor porta nunc, id interdum ipsum purus vel
dolor.}
\end{document}

在此处输入图片描述

我加载了 eso-pic,然后简单地将图片移到了前台。如果你想多次执行此操作,为此编写一个宏可能会更方便(我很乐意协助你完成这项任务)。请注意,我必须重新缩放图片,因为我只有你问题的屏幕截图。

答案2

使用我的解决方案上一个问题这项工作很顺利:-):

在此处输入图片描述

\documentclass{article}
\usepackage{graphicx}
% for indentation of a text in mini page
\parskip=1ex    %  just drop if you not like it
\newcommand{\saveparinfos}{%
\edef\myindent{\the\parindent}%
\edef\myparskip{\the\parskip}}

\newcommand{\useparinfo}{%
\setlength{\parindent}{\myindent}%
\setlength{\parskip}{\myparskip}}
\saveparinfos
% color boxes
\usepackage{xcolor}
\newcommand\ColorBox[2]%
{\noindent\hspace*{-\dimexpr2\fboxsep+2\fboxrule\relax}\mbox{
\fcolorbox{#1}{#1}{%
\begin{minipage}{\linewidth}%
#2
\end{minipage}}}\par
}
\newcommand\ColorFBox[2]%
{\noindent\hspace*{-\dimexpr2\fboxsep+2\fboxrule\relax}
 \setlength\fboxrule{1pt}
\fcolorbox{#1}{#1!30}{%
\begin{minipage}{\linewidth}
#2
\end{minipage}}\par
}

% dummy text
\usepackage{lipsum}

\begin{document}
\ColorBox{blue!30}{\useparinfo
\lipsum[11]
    \begin{center}
\includegraphics{Capture}
    \end{center}
\lipsum[11]
}
\end{document}

附录:

一个简单的解决方案,它可以为注释框启用圆角以及渐变着色,并且可以包含图像而不会出现您所报告的问题。全部借助于tcolorbox

\documentclass[a4paper]{article}
\usepackage[many]{tcolorbox}
\tcbset{oversize,
        enhanced,
        colframe=red!75!black,
        interior style={top color=blue!10,
                        bottom color=red!50}
        }
\usepackage{lipsum}

\begin{document}
\lipsum[11]
\begin{tcolorbox}
\lipsum[11]
\begin{center}
\includegraphics{Capture}
    \end{center}
\lipsum[11]
\end{tcolorbox}
\end{document}

在此处输入图片描述

当然,您可以命名/定义自己的颜色盒。如果您还将它们用于具有不同功能的其他用途,这是特别明智的。

相关内容