TransWikia.com

How do I get a definition and theorem environment like these?

TeX - LaTeX Asked on May 23, 2021

enter image description here

I tried using the mdframed package but I failed, how can I get that output?

One Answer

A solution can be obtained using the 'tcolorbox' package. There are many possibilities. I sketched three (in the example below). In the first section, I tried to stick to your wished style with separate titles for the theorem-like environments.

In the second section, the construction is easier; the lemma is obtained using directly an example from the manual (almost). But you don't have separate title lines.

enter image description here enter image description here

There is still another possibility indicated in the manual on page 339 using newtcbtheorem, but the labels for cross-references and strangely defined. Personally I don't like it.

documentclass[11pt, a4paper]{article}
usepackage[top=105pt, bottom=75pt, left=75pt, right=75pt]{geometry}
setlength{headsep}{15pt}
setlength{footskip}{45pt}

usepackage{xcolor}
usepackage{lipsum}

usepackage{amsmath, amssymb, amsthm}
usepackage{ifthen}
usepackage{tikz}
usetikzlibrary{calc}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
usepackage{tcolorbox}
tcbuselibrary{skins, breakable}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% with separate title
xdefinecolor{thmTopColor}{RGB}{102, 102, 238}
xdefinecolor{thmBackColor}{RGB}{245, 245, 255}  % white


newenvironment{thmbox}[1]{%
  tcolorbox[%
  empty,
  parbox=false,
  noparskip,
  enhanced,
  breakable,
  sharp corners,
  boxrule=-1pt,
  left=2ex,
  right=0ex,
  top=0ex,
  boxsep=1ex,
  before skip=2.5ex plus 2pt,
  after skip=2.5ex plus 2pt,
  colback=thmBackColor,
  colframe=white,
  coltitle=black,
  colbacktitle=thmBackColor,
  fonttitle=bfseries,
  title=#1,
  titlerule=1pt,
  titlerule style=thmTopColor,
  overlay unbroken and last={%
    draw[color=thmTopColor, line width=1.25pt]
    ($(frame.north west)+(.5em, -4.1ex)$)
    -- ($(frame.south west)+(.5em, 1ex)$) -- ++(2em, 0);
  }]
}{endtcolorbox}

newenvironment{thmb}[1][]{% before
  refstepcounter{thm}%
  ifthenelse{equal{#1}{}}{%
    begin{thmbox}{Theorem thethm.}itshapehspace{-.75ex}%
  }{%
    begin{thmbox}{Theorem thethm%
        hspace{.75ex}(textnormal{#1}).}itshapehspace{-.75ex}
    }}
  {end{thmbox}
}
  
  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%%% simple forms
% 1
newtheorem{thm}{Theorem}[section]

theoremstyle{definition}
newtheorem{definition}[thm]{Definition}


newenvironment{noticeB}[1][]{%
  ifthenelse{equal{#1}{}}{%
    colorlet{cbackground}{white}
  }{colorlet{cbackground}{#1}}
  tcolorbox[%
  notitle,
  empty,
  enhanced,  % delete the edge of the bottom page for a broken box
  breakable,
  coltext=black,
  colback=cbackground, 
  fontupper=rmfamily,
  parbox=false,
  noparskip,
  sharp corners,
  boxrule=-1pt,  % width of the box' edges
  frame hidden,
  left=.5parindent,  % inner space from text to the left edge
  right=.5parindent,
  top=5pt,
  bottom=5pt,
  % boxsep=0pt,
  before skip=2.5ex plus 2pt,
  after skip=2.5ex plus 2pt,
  borderline west = {1.5pt}{-0.1pt}{blue!30!black}, % second argument = offset
  overlay unbroken and last={%
    draw[color=black, line width=1.25pt]
    ($(frame.south west)+(1.pt, -0.1pt)$) -- ++(2em, 0);
  }
  ]}
{endtcolorbox}


newenvironment{thmB}{begin{thm}begin{noticeB}[blue!50!black!5]}
    {end{noticeB}end{thm}}
newenvironment{definitionB}{begin{definition}begin{noticeB}}{%
    end{noticeB}end{definition}}


%2
newtheorem{lem}[thm]{Lemma}% from 'amsthm'
tcolorboxenvironment{lem}{%
  enhanced jigsaw,
  boxrule=-1pt,
  colframe=white,
  borderline west={2pt}{0pt}{orange},  % second argument is the offset
  interior hidden,
  breakable,
  before skip=2.5ex plus 2pt,
  after skip=2.5ex plus 2pt
}

begin{document}

section{Based on texttt{tcolorbox} with titles}

begin{thmb}
  label{th:test}
  lipsum[5]
end{thmb}

lipsum[1]

begin{thmb}[Anonymous]
  label{th:test2}
  lipsum[6]
end{thmb}

Can we make a reference to Theorem ref{th:test}?  Yes we can.



section{With simpler definitions for the theorem-like environmants}

begin{definitionB}
  lipsum[1]
end{definitionB}

lipsum[2]

begin{thmB}
  lipsum[5]
end{thmB}

lipsum[4]

begin{lem}[from texttt{tcolorbox} manual]
  lipsum[7]
end{lem}
end{document}

Answered by Daniel N on May 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP