1

I am using XeLateX. How can i add a gradient in every new theorem,lemma etc like the image below? I want the gradient to fill the whole width of the line. How can this be done automatically? enter image description here

My code

\documentclass[letterpaper,twoside,reqno,10pt]{book}

\usepackage[cm-default]{fontspec}
\usepackage{xltxtra}
\usepackage{xunicode}
\usepackage{xgreek}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{bold-extra}
\usepackage{fancyhdr}%renewcommend chaptername
\usepackage[left=2.5cm,right=2.5cm,top=2cm,bottom=1.6cm]{geometry} %
\usepackage{enumerate}
\usepackage{float}%text next2 image
\usepackage{cancel}%diagrafi metablitwn kathetos
\usepackage{empheq}
\usepackage{makeidx} % needed for creating an index
\usepackage{wrapfig}
\usepackage{amsthm}
\usepackage{thmtools}
% % % % % % % Me to style twn paradeigmatwn % % % % % % %
\declaretheoremstyle[headfont=\normalfont\bfseries]{normal}
\declaretheorem[style=normal,numberwithin=section,name=Παράδειγμα]    {example}
\declaretheorem[style=normal,sibling=example,name=Σχόλιο]{sxolio}
\declaretheorem[style=normal,sibling=example,name=Πόρισμα]{corollary}
\declaretheorem[style=normal,sibling=example,name=Εφαρμογή]{application}
\declaretheorem[style=normal,sibling=example,name=Άσκηση]{homework}
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % % % Me to style twn thewrimatwn % % % % % % % % % % 
\declaretheorem[name=ΘΕΩΡΗΜΑ,numberwithin=section]{theorem}
\declaretheorem[name=ΛΗΜΜΑ,numberwithin=section]{lemma}
\declaretheorem[name=ΠΡΟΤΑΣΗ,numberwithin=section]{proposition}
\declaretheorem[name=ΟΡΙΣΜΟΣ,numberwithin=section]{definition}
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% % % % %OTF fonts % % % % % % % % % % % % % % % % % % % % % % % % % % % 
\setmainfont[BoldFont=Kerkisbold,
         ItalicFont=Kerkisitalics]{Kerkis}
\setsansfont{KerkisSans}
% % % % % % % % % % % % % % % % % % % % % % % % %
\begin{document}
\chapter{test}
\section{test}   
  \begin{theorem}\ \\
   This is a theorem
  \end{theorem}

  text out of theorem

\begin{sxolio}\ \\
This is a comment
\end{sxolio}
\end{document}

1 Answers1

2

If you are using the base \newtheorem, you can use

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shadings}

\newtheorem{theorem}{Theorem}[section]

\makeatletter
\def\@begintheorem#1#2{\trivlist
\item[\hskip \labelsep{\tikz[overlay]{\shade[left color=blue!50,right color=white]
  (0,-1ex) rectangle (\textwidth-\labelsep,1em);}%    
  \bfseries #1\ #2}]\itshape}
\def\@opargbegintheorem#1#2#3{\trivlist
\item[\hskip \labelsep{\tikz[overlay]{\shade[left color=blue!50,right color=white]
  (0,-1ex) rectangle (\textwidth-\labelsep,1em);}% 
  \bfseries #1\ #2\ (#3)}]\itshape}
\makeatother

\begin{document}

\section{first}

\begin{theorem}
\textbf{(Pythagorean Theorem)}\newline
Text goes here
\end{theorem}
\end{document}

demo


For thmtools you can put the tikz overlay in the headfont. (This was slightly complicated because the default headindent was \empty, not 0pt.)

\documentclass{book}
\usepackage{amsthm}
\usepackage{thmtools}

\newlength\templen

\makeatletter
\def\titleshade{\ifx\empty\thmt@style@headindent\relax \def\thmt@style@headindent{0pt}\fi
  \tikz[overlay,xshift=\thmt@style@headindent]{\shade[left color=blue!30,right color=white]
  (0,-1ex) rectangle (\linewidth-\thmt@style@headindent,1em);}}%
\makeatother

\declaretheoremstyle[headfont=\titleshade\normalfont\bfseries,postheadspace=\newline]{shaded}
\declaretheorem[style=shaded,name=Theorem,numberwithin=section]{theorem}

\usepackage{tikz}

\begin{document}
\chapter{test}
\section{test}   
  \begin{theorem}[Pythagorean Theorem]
   This is a theorem
  \end{theorem}

text out of theorem

\end{document}
John Kormylo
  • 79,712
  • 3
  • 50
  • 120