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}
5
  • Related: Section title gradient
    – Werner
    Mar 3, 2016 at 6:29
  • I've seen this answer but it works only for sections,chapters using the package titlesec. How can it work for theorems, lemmas etc ?
    – C. Apollon
    Mar 3, 2016 at 15:33
  • Which theorem package are you using? A MWE would be nice. Mar 3, 2016 at 16:01
  • Thanks for your reply! I'm new to Latex/XeLatex so i am sorry if this is easy, but i couldn't find it. Is this MWE good?
    – C. Apollon
    Mar 3, 2016 at 17:59
  • It could be a bit more minimal. Right now I can't run it and can't figure out which packages I have to remove (e.g. where B.mf is coming from). Mar 3, 2016 at 18:44

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .