使用背景包控制丝带颜色

使用背景包控制丝带颜色

我指的是这个答案用于绘制具有可变弯曲点的丝带。基于薛定谔猫的代码,我无法在使用背景包的同时制作白色丝带。以下代码基于薛定谔猫的答案,并进行了微小的更改,并与背景包结合,制作了一条(据称)白色丝带。所使用的背景图像可以在这里。但结果是,丝带是透明的,而不是白色的,显示了背景图像。我想我需要强制丝带覆盖背景图像,但不知道如何调整代码来反映这一点。

\documentclass[a0, landscape]{sciposter} 
\usepackage[all]{genealogytree}               
\usepackage{graphicx}                        
\usepackage{yfonts}
\usepackage{suetterl}
\usepackage{txfonts}
\usepackage{tikz}
\usepackage{pagecolor} 
\usepackage[pages=some]{background}


\backgroundsetup{
    scale=1,
    color=black,
    opacity=0.6,
    angle=0,
    contents={%
        \includegraphics[width=\paperwidth,height=\paperheight]{Tigerramki}
    }%
    hshift = -3cm, % horizontal margin
    vshift = -3cm  % vertical margin
}


\usetikzlibrary{calc}
\tikzset{pics/ribbon/.style={code={
            \def\pv##1{\pgfkeysvalueof{/tikz/ribbon/##1}}
            \node[alias=aux,/tikz/ribbon/node]{#1};
            \fill[\pv{shadow color}]
            (aux.north west) arc(-90:-270:\pv{arc radius}) 
            -- ++ (\pv{inset},0) arc(-90:00:\pv{arc radius})
            -- ([xshift=\pv{inset}+\pv{arc radius}]aux.north west)
            (aux.north east) arc(-90:90:\pv{arc radius}) 
            -- ++ (-\pv{inset},0) arc(-90:-180:\pv{arc radius})
            -- ([xshift=-\pv{inset}-\pv{arc radius}]aux.north east);
            \draw let \p1=($(aux.north)-(aux.south)$) in 
            % little stretch south west
            (aux.south west) arc(-90:-180:\pv{arc radius}) -- ++ (0,\y1)
            % big stretch north west 
            (aux.north west) arc(-90:-270:\pv{arc radius}) 
            -- ++ (\pv{inset},0) arc(-90:90:\pv{arc radius}) 
            -- ++ (-\pv{outset},0) -- ++(\y1/2,-\y1/2)
            -- ++(-\y1/2,-\y1/2) -- 
            ([yshift=4*\pv{arc radius},xshift=-\pv{arc radius}]aux.south west)
            % little stretch south east
            (aux.south east) arc(-90:0:\pv{arc radius}) -- ++ (0,\y1)
            % big stretch north east 
            (aux.north east) arc(-90:90:\pv{arc radius}) 
            -- ++ (-\pv{inset},0) arc(-90:-270:\pv{arc radius}) 
            -- ++ (\pv{outset},0) -- ++(-\y1/2,-\y1/2)
            -- ++(\y1/2,-\y1/2) -- 
            ([yshift=4*\pv{arc radius},xshift=\pv{arc radius}]aux.south east)
            % top
            (aux.north west) -- (aux.north east)
            % bottom
            (aux.south west) -- (aux.south east);
    }},
    ribbon/.cd,node/.style={align=center,inner xsep=5pt},%<- controls the node options
    arc radius/.initial=2pt,%<- self-explaining (?)
    inset/.initial=1cm,%<- horizontal distance of the lower horizontal stretches
    outset/.initial=2cm,%<- horizontal distance of the upper horizontal stretches
    outer/.style={draw},%<- left and right band of the ribbon
    shadow color/.initial=gray!80}%<- self-explaining (?)
\newcommand{\TikZRibbon}[2][]{\begin{tikzpicture}
    \tikzset{ribbon/.cd,#1}
    \pic{ribbon={#2}};
    \end{tikzpicture}}


\begin{document} 
    \pagecolor{white} 
    \BgThispage


\begin{center} \TikZRibbon[node/.append style={font=\Huge,inner xsep=5em},inset=2cm,outset=5cm, outer/.append style={fill=white}]{%
    This ribbon should be white but it's not~} 
\end{center} 

\end{document} 

在此处输入图片描述

答案1

我认为下面的讨论有点误解这个帖子。工作中有两种不同的丝带,一种是更基本的丝带,即上层版本,另一种是更花哨的丝带,即下层代码。更花哨的丝带可以填充。

\RequirePackage{xcolor}
\documentclass[a0, landscape]{sciposter} 
% the following packages are not used in the MWE 
%\usepackage[all]{genealogytree}               
%\usepackage{graphicx}                        
%\usepackage{yfonts}
%\usepackage{suetterl}
%\usepackage{txfonts}
%\usepackage{pagecolor} 
\usepackage[pages=some]{background}
\usepackage{tikz}


\backgroundsetup{
    scale=1,
    color=black,
    opacity=0.6,
    angle=0,
    contents={%
\includegraphics[width=\paperwidth,height=\paperheight]{example-image-duck}
    }%
    hshift = -3cm, % horizontal margin
    vshift = -3cm  % vertical margin
}


\usetikzlibrary{calc}
\tikzset{pics/ribbon/.style={code={
\def\pv##1{\pgfkeysvalueof{/tikz/ribbon/##1}}
\node[alias=aux,/tikz/ribbon/node]{#1};
\path[ribbon/shadow]
(aux.north west) arc(-90:-270:\pv{arc radius})
-- ++ (\pv{inset},0) arc(-90:00:\pv{arc radius})
-- ([xshift=\pv{inset}+\pv{arc radius}]aux.north west);
\path[ribbon/shadow] (aux.north east) arc(-90:90:\pv{arc radius})
-- ++ (-\pv{inset},0) arc(-90:-180:\pv{arc radius})
-- ([xshift=-\pv{inset}-\pv{arc radius}]aux.north east);
\path[ribbon/outer] let \p1=($(aux.north)-(aux.south)$) in
% little stretch south west
(aux.south west) arc(-90:-180:\pv{arc radius}) -- ++ (0,\y1)
arc(180:270:\pv{arc radius}) -- cycle
% little stretch south east
(aux.south east) arc(-90:0:\pv{arc radius}) -- ++ (0,\y1)
arc(0:-90:\pv{arc radius}) --cycle;
\path[ribbon/back] let \p1=($(aux.north)-(aux.south)$) in
% big stretch north west
([xshift=-\pv{arc radius},yshift=\pv{arc radius}]aux.north west) arc(180:90:\pv{arc radius})
-- ++ (\pv{inset},0) arc(-90:90:\pv{arc radius})
-- ++ (-\pv{outset},0) -- ++(\y1/2,-\y1/2)
-- ++(-\y1/2,-\y1/2) --
([yshift=4*\pv{arc radius},xshift=-\pv{arc radius}]aux.south west)
-- cycle
% big stretch north east
([xshift=\pv{arc radius},yshift=\pv{arc radius}]aux.north east)
arc(0:90:\pv{arc radius})
-- ++ (-\pv{inset},0) arc(-90:-270:\pv{arc radius})
-- ++ (\pv{outset},0) -- ++(-\y1/2,-\y1/2)
-- ++(\y1/2,-\y1/2) --
([yshift=4*\pv{arc radius},xshift=\pv{arc radius}]aux.south east)
-- cycle
% top
(aux.north west) -- (aux.north east)
% bottom
(aux.south west) -- (aux.south east);
}},
ribbon/.cd,node/.style={align=center,inner xsep=5pt},%<- controls the node options
arc radius/.initial=3pt,%<- self-explaining (?)
inset/.initial=1cm,%<- horizontal distance of the lower horizontal stretches
outset/.initial=2cm,%<- horizontal distance of the upper horizontal stretches
back/.style={draw},%<-ribbon pieces in the background
outer/.style={draw},%<- left and right band of the ribbon
shadow/.style={fill=gray!80}}%<- self-explaining (?)
\newcommand{\TikZRibbon}[2][]{\begin{tikzpicture}
    \tikzset{ribbon/.cd,#1}
    \pic{ribbon={#2}};
    \end{tikzpicture}}


\begin{document} 
    \pagecolor{white} 
    \BgThispage


\begin{center}
\TikZRibbon[node/.append style={font=\Huge,inner xsep=5em,
inner ysep=0.5em,fill=white},
outer/.append style={fill=white},
back/.append style={fill=white},inset=2cm,outset=5cm]{%
This ribbon is white as it should be.}
\end{center} 

\end{document} 

在此处输入图片描述

请注意,我没有该Tigerramki文件,因此我使用了通用背景图形。此外,您的代码会导致警告Package xcolor Warning: Incompatible color definition on input line 77.,这是由于sciposter代码非常古老并且正在加载color而不是xcolor。这个警告​​与此答案的范围没有直接关系,但我通过\RequirePackage{xcolor}在最顶部添加来修复它。我还注释掉了 MWE 不需要的包(但当然可以使用它们)。

相关内容