多个 tikz 路径在多个方向上衰落

多个 tikz 路径在多个方向上衰落

我想创建一个定理装饰。下面是一个简单的示例:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}

\newcommand{\theoremname}{Theorem}
\newcounter{theorem}

\newlength{\theoremrulewidth}
\setlength{\theoremrulewidth}{.4\textwidth}
\newenvironment{theorem}[1][\relax]
  {\refstepcounter{theorem}%
    \tikz[remember picture, overlay] \fill [left color = orange, right color = white, draw = white] 
      (0pt,-.1\baselineskip) -- (0pt,.9\baselineskip) -- (\theoremrulewidth,.9\baselineskip) -- 
        (\theoremrulewidth,\dimexpr.9\baselineskip-1pt) -- (1pt,\dimexpr.9\baselineskip-1pt) -- (1pt,-.1\baselineskip) -- cycle;
   \textcolor{orange}{~\theoremname~\thetheorem}
   \quad}
  {%
   \hfill\null%
   \tikz[remember picture, overlay] \fill [right color = orange, left color = white, draw = white] 
     (0pt,.5\baselineskip) -- (0pt,-.5\baselineskip) -- (-\theoremrulewidth,-.5\baselineskip) -- 
       (-\theoremrulewidth,\dimexpr-.5\baselineskip+1pt) -- (-1pt,\dimexpr-.5\baselineskip+1pt) -- (-1pt,.5\baselineskip) -- cycle;
  }

\begin{document}

\begin{theorem}
This is a theorem with ascenders and descenders, p-really.
\end{theorem}

\end{document}

两条水平线都淡化为white。我还想将两条垂直线淡化为white。是否可以将其淡化为完全透明?对于顶部规则,除了现有的 和 之外,还使用​​和颜色orange的组合没有帮助;对于底部规则也是如此。top colorbottomleft colorright color

请注意我如何创建一个宽度的多边形,1pt而不是设置一条常规线。我相信有更好的方法来做到这一点。

答案1

使用\shade而不是\fill并分别绘制每个部分(水平分量和垂直分量);例如:

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\shade[left color=orange]
  (0,0) -- ++(-4pt,4pt) -- ++(5,0) -- ++(0,-4pt) -- cycle;
\shade[top color=orange]
  (0,0) -- ++(-4pt,4pt) -- ++(0pt,-5) -- ++(4pt,0) -- cycle;
\end{tikzpicture}

\end{document}

在此处输入图片描述

这里只是水平部分,这样你就可以看到左端产生了一个角度,然后由垂直部分完成:

\documentclass[10pt]{article}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
\shade[left color=orange]
  (0,0) -- ++(-4pt,4pt) -- ++(5,0) -- ++(0,-4pt) -- cycle;
%\shade[top color=orange]
  %(0,0) -- ++(-4pt,4pt) -- ++(0pt,-5) -- ++(4pt,0) -- cycle;
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

那这个呢?

结果

\newcommand{\theoremname}{Theorem}
\newcounter{theorem}

\newlength{\theoremrulewidth}
\setlength{\theoremrulewidth}{.4\textwidth}
\newenvironment{theorem}[1][\relax]
  {\refstepcounter{theorem}%
    \tikz[remember picture, overlay, baseline=-.9\baselineskip]{
       \fill[left color = orange, right color = white] 
           (0,0) rectangle +(\theoremrulewidth, -1pt);
       \fill[top color = orange, bottom color = white] 
           (0,0) rectangle +(1pt, -.9\baselineskip);
    }
   \textcolor{orange}{~\theoremname~\thetheorem}
   \quad}
  {%
   \hfill\null%
   \tikz[remember picture, overlay, baseline=0.4\baselineskip] {
       \fill[right color = orange, left color = white] 
           (0,0) rectangle +(-\theoremrulewidth, -1pt);
       \fill[bottom color = orange, top color = white] 
           (0,0) rectangle +(1pt, .9\baselineskip);
  } 
}


\begin{theorem}
This is a theorem with ascenders and descenders, p-really.
\end{theorem}

答案3

这是我的尝试tcolorbox

\documentclass{article}

\newcommand{\theoremname}{Theorem}
\newcounter{theorem}

\newlength{\theoremrulewidth}
\setlength{\theoremrulewidth}{.4\textwidth}
\newenvironment{theorem}[1][\relax]
  {\refstepcounter{theorem}%
    \begin{mybox}%
   \noindent\textcolor{orange}{~\theoremname~\thetheorem}
   \quad}%
  {%
   \hfill\null%
   \end{mybox}
  }

\usepackage{tcolorbox}
\tcbuselibrary{skins}
\usetikzlibrary{positioning,shadows}  
  \newtcolorbox{mybox}{%
    enhanced,
    top=0pt,
    left=0pt,
    bottom=0pt,
    right=0pt,
    width=\textwidth,
    colframe=white,
    colback=white,
    overlay={
    \draw[thick,orange,path fading=east]([xshift=-0.4pt]frame.north west) rectangle ([xshift=-1cm]frame.north);
    \draw[thick,orange,path fading=south]([xshift=-0.4pt]frame.north west) rectangle (frame.south west);
    \draw[thick,orange,path fading=west]([xshift=-0.4pt]frame.south east) rectangle ([xshift=1cm]frame.south);
    \draw[thick,orange,path fading=north]([xshift=-0.4pt]frame.south east) rectangle (frame.north east);
    }
}

\begin{document}

\begin{theorem}
This is a theorem with ascenders and descenders, p-really.
\end{theorem}

\end{document}

在此处输入图片描述

相关内容