19

I recently read a book Algorithm Design by Jon Kleinberg and Eva Tardos, which is written in a very unique style. This book doesn't have any typical LaTeX environments such as theorem, lemma, and corollary as in CLRS textbook. Instead, all these important blocks are numbered sequentially.

For example, this image is captured from page 7 in chapter 1 of the KT textbook, which is available from the publisher's website. (This page explains Gale-Shapley's algorithm for Stable Marriage Problem.)

enter image description here

As you can see, the block numbered (1.1) and (1.2) can be Lemma in the usual textbook and (1.3) can be theorem. I love their writing style and I want to mimic it.


My Question: What is the best way to mimic this style of writing? Let's say that I want to define an environment textblock which does the following to copycat KT style of writing.

  1. This environment can be either shaded or not. (As shown in the above picture, (1.3) block is shaded while (1.1) and (1.2) are not.)
  2. The numbering of this environment includes chapter number.
  3. I'd like this block spans across the entire textwidth.

How can I define such an environment?

2 Answers 2

25

Here's an implementation with amsthm and tcolorbox:

\documentclass{article}

\usepackage{lipsum} % just for the example

\usepackage{amsthm,tcolorbox}

\newtheoremstyle{block}
 {\topsep}% space above
 {\topsep}% space below
 {\itshape}% body font
 {}% indent
 {\bfseries}% head font
 {}% punctuation
 {1em}% space between head and body
 {(\thmnumber{#2})}

\theoremstyle{block}
\newtheorem{block}{}[section]
\newtheorem{block*}[block]{}

\tcolorboxenvironment{block*}{
  frame empty,
  colback=black!15!white,
  grow to left by=6pt,
  grow to right by=6pt,
  left=1.6pt,
  right=1.6pt,
  arc=0pt
}

\begin{document}

\section{Whatever}

\lipsum[2]

\begin{block}
Some text to see what happens,
some text to see what happens,
some text to see what happens,
some text to see what happens.
\end{block}

\lipsum[2]

\begin{block*}
Other text that should be the statement of
an important theorem, so it is on a grey
background.
\end{block*}

\lipsum[2]

\end{document}

enter image description here

3

One approach without any package except xcolor for the shaded block:

MWE

\documentclass[a4paper]{article}
\usepackage[margin=1cm]{geometry} % little margin for MWE
\usepackage{lipsum} % dummy text for MWE
\usepackage{xcolor} % for shaded gray block
\newcounter{para}[section]\setcounter{para}{0}
\def\block#1{%
  \refstepcounter{para}
  \bigskip 
  \noindent\textbf{(\thesection.\thepara)}\quad{\em #1}
  \par\bigskip}
\def\blockg#1{ %
  \refstepcounter{para}
 \bigskip 
 \fboxsep1em
 \noindent\fcolorbox{gray!40}{gray!20}{
 \begin{minipage}{\dimexpr\linewidth-2em}
    \noindent\textbf{(\thesection.\thepara)}\quad\em#1
 \end{minipage}}
 \par\bigskip}

\begin{document}
\section{Lore ipsum}    
\lipsum[11]         % normal text
\block{\lipsum[2]}  % block 1.1
\lipsum[3]          % normal text
\blockg{\lipsum[4]} % block 1.2
\lipsum[5]          % normal text
\section{Dolor sit amet}    
\lipsum[12]         % normal text
\block{\lipsum[13]} % block 2.1
\end{document}

You must log in to answer this question.

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