6

I'd like to create a theorem decoration. Here's a quick take on one:

enter image description here

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

Both horizontal rules fade to white. I'd like to also fade both vertical rules to white. Would it be possible to fade it to fully transparent orange? For the top rule, using a combination of top color and bottom color in addition to the existing left color and right color doesn't help; similar for the bottom rule.

Note how I create a polygon of width 1pt rather than set a regular line. I'm sure there's a better way to do this.

4
  • Draw the vertical rectangles separately and then you can use top color, bottom color. May 27, 2014 at 22:03
  • @GonzaloMedina: Yes, I tried that... then there is a not-so pleasant overlay of the two at the connection point due to the draw=white option. Even when I set the line width to 0pt, there is a mild artifact in the output... Try it and see, or suggest some alternatives. I'm not that skilled with tikz.
    – Werner
    May 27, 2014 at 22:05
  • This question tex.stackexchange.com/a/173538/1952 want similar lines although without corners
    – Ignasi
    May 27, 2014 at 22:08
  • Also this question maybe similar: tex.stackexchange.com/a/134297/31034
    – user31034
    May 27, 2014 at 22:10

3 Answers 3

4

Use \shade instead of \fill and draw each portion (horizontal component and vertical component) separately; as an example:

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

enter image description here

An here's just the horizontal component, just so that you can see the left end is produced with an angle that then will be completed by the vertical portion:

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

enter image description here

3
  • Ha! We had the same idea. Btw, isn't \shade simply a shortcut for \fill[shade] ?
    – JLDiaz
    May 27, 2014 at 23:18
  • @JLDiaz Until today I thought so, but apparently they are not equivalent; using \fill[shade,...] instead of \shade[...] with my code produces some artifacts. May 27, 2014 at 23:22
  • @JLDiaz: \fill simply does not work with shade. - I do not know why. tex.stackexchange.com/questions/169807/… May 28, 2014 at 14:21
2

What about this?

Result

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

Here is my try with 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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.