2

This is the first time that I'm going to prepare a book with Latex. I am not so familiar with advanced options of Latex, and in particular with typography. The book includes a lot of examples and problems, but I don't want to write the number of each one because Latex can do it. I have attached a sample page of a book and I want to follow exactly the same style. I will appreciate it if someone helps me. For example, all examples are boxed, and all problems are in a gray box with a thick line at the bottom. The difficult problems are denoted by a star sign. Also, I want to adjust the space of items once for all (I mean, for example, the spacing between the problem and solution), so that I don't have to adjust it each time. sample

\documentclass[11pt]{book}
\usepackage{hyperref}
\usepackage{amsmath}
\usepackage{graphicx}


\begin{document}
\title{Quantum Mechanics}
\author{My name}
\maketitle


\chapter{Wave Function}
\section{Schrodinger equation}
I'm going to show the first example

\boxed{
Example 1.1
This is the question. Following is the solution
\textbf{Solution:} And here is the solution
}

\textbf{* Problem 1.1}
 Do the followings:

(a) Compute x.

(b) compute y.


\chapter{second}

\chapter{third}
\end{document}
  • 2
    tcolorbox may be a good choice for such things. It allows you to produce numbered environments that have shaded backgrounds, and much more. Here is a (random) example. – user121799 Jan 29 '19 at 22:25
1

This is to give you a start. No attempt of reproducing your screen shot is made.

  1. tcolorbox is used to create environments of the type you seem to seek. I mainly adapted them from this answer.
  2. There is no need to hard-code the number of the examples, nor the items of the list. Rather, this is done by tcolorbox and enumerate in the following example. Of course, there are many more ways of producing auto-numbered environments such as theorems.

\documentclass[11pt]{book}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage{tcolorbox}
\tcbuselibrary{skins,breakable}
\usepackage{enumerate}

\newtcolorbox[auto counter, number within=chapter, 
    crefname={example}{examples},
    Crefname={Example}{Examples},
    number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]
    {myexample}[2][]{%
    enhanced,
    breakable,
    fonttitle=\bfseries,
    title=Example~\thetcbcounter: #2,    
    #1
}


\newtcolorbox[auto counter, number within=chapter, 
    crefname={example}{examples},
    Crefname={Example}{Examples},
    number freestyle={\noexpand\thechapter.\noexpand\arabic{\tcbcounter}}]
    {myproblem}[2][]{%
    enhanced,
    breakable,
    fonttitle=\bfseries,
    title=Problem~\thetcbcounter: #2,    
    #1
}

\begin{document}
\title{Quantum Mechanics}
\author{My name}
\maketitle


\chapter{Wave Function}
\section{Schr\"{o}dinger equation}
I'm going to show the first example


\begin{myexample}[label=first]{First example}
  This is the question. Following is the solution.

\textbf{Solution:} And here is the solution
\end{myexample}

\begin{myexample}[label=second]{Second example}
  \dots
\end{myexample}

\chapter{Second chapter}

\begin{myexample}[label=third]{Third example}
  \dots
\end{myexample}

\Cref{second} gives us some idea as seen from \cref{first}.

\begin{myproblem}[label=third]{}
 Do the followings:
 \begin{enumerate}[(a)]
   \item Compute $x$.
   \item Compute $y$.
 \end{enumerate}
\end{myproblem} 

\chapter{second}

\chapter{third}



\end{document}

And this is an example of what this gives you.

enter image description here

I understand that this does not reproduce your screen shot. However, I am convinced that a look in the tcolorbox manual will allow you to achieve these things.

|improve this answer|||||

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.