0

I'm using thmbox and it seems it does not properly understand page size. When it splits a box between pages, sometimes it writes over the page number. Is this an error in my document, or is it that extreport does not play well with thmbox, or is this simply a bug in thmbox? Is there a way I can fix it? If I completely turn of cutting as explained here, it no longer writes over the page number, but it now refuses to cut boxes between pages, which is not good for long theorems, etc.

I'm including a pretty small working example. It is difficult to produce a really short example at it seems to be triggered by long documents. This LaTeX code produces a 5 page document. You can see the error at the bottom of page 4 where the definition of determinant cuts between pages, and the page number (4) is written over by the math formula. $a_{1k}$

Formula writes over page number

Here is a zoomed out view of the confused definition.

Definition with theorem box

I also notice the math equation falls outside the theorem box. Perhaps it is something to do with extreport and math mode? However, I only see then problem with equations inside the box.

\documentclass[14pt]{extreport}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{thmbox}

\newtheorem[bodystyle=\normalfont\noindent]{theorem}{Theorem}[section]
\newtheorem[bodystyle=\normalfont\noindent]{definition}[theorem]{Definition}

\newcommand\jleft{\mathopen{}\mathclose\bgroup\left}
\newcommand\jright{\aftergroup\egroup\right}
\newcommand\jparen[1]{\jleft(#1\jright)}
\newcommand\supress[2]{{\mathfrak{S}_{#2}\jparen{#1}}}
\newcommand\cvec[1]{\begin{bmatrix} #1 \end{bmatrix}}
\newcommand{\abs}[1]{{\left| #1 \right|}}

\title{Practical Linear Algebra}
\author{Jim Newton}
\begin{document}

\chapter{Matrices}
\label{ch.matrices}
\section{Definition}

What is a matrix?

\begin{enumerate}
\item Mathematical definition.
\item Representing in Python
\end{enumerate}

\section{Addition}

Matrices are added component-wise.
If two matrices $A$ and $B$ each have dimensions $n\times m$, i.e., $n$ rows and $m$ columns,
then the can be added and the compnent in the row $i$ column $j$ of the sum
is exactly $c_{ij}=a_{ij}+b_{ij}$.
\begin{align*}
  \begin{bmatrix}
    a_{11}&a_{12}&\cdots&a_{1m}\\
    a_{21}&a_{22}&\cdots&a_{2m}\\
    \vdots & \vdots &&\vdots\\
    a_{n1}&a_{n2}&\cdots&a_{nn}
  \end{bmatrix} +
  \begin{bmatrix}
    b_{11} & b_{12}  &\cdots & b_{1n}\\
    b_{21} & b_{22}  &\cdots & b_{2n}\\
    \vdots & \vdots &       & \vdots\\
    b_{n1}  & b_{n2} &\cdots & b_{nn}
  \end{bmatrix} =\\
  \begin{bmatrix}
    a_{11}+b_{11} & a_{12}+b_{12} & \cdots & a_{1n}+b_{1n}\\
    a_{21}+b_{21} & a_{22}+b_{22} & \cdots & a_{2n}+b_{2n}\\
    \vdots & \vdots & &\vdots\\
    a_{n1}+b_{n1} & a_{n2}+b_{n2} & \cdots & a_{nn}+b_{nn}
  \end{bmatrix}
\end{align*}

Matrix addition is commutative when the components are themselves
commutative.  For example if the components are integers or real
numbers.

The $n\times m$ zero matrix is the additive identity for the set of $n\times m$ matrices.

\section{Multiplication}
Two matrices, $A$ and $B$, can be multiplied if their dimensions are
compatible.  The requirement is that an $n\times k$ (on the left) can
be multiplied by a $k \times n$ matrix to obtain an $n\times m$
matrix.

Matrix multiplication is, in general, not commutative.  However, there
do exist pairs of matricies which are commutative under
multiplication.  E.g., $A^n \times A^m = A^{n+m} = A^{m+n} = A^m\times
A^n$.  Also if a matrix is invertable, then $A \times A^{-1} = I =
A^{-1}\times A$.

We may multiply two matricies
\begin{align*}
  A &= \begin{bmatrix}
    a_{11}&a_{12}&\cdots&a_{1k}\\
    a_{21}&a_{22}&\cdots&a_{2k}\\
    \vdots & \vdots &&\vdots\\
    a_{n1}&a_{n2}&\cdots&a_{nk}
  \end{bmatrix}\\
  B &=
  \begin{bmatrix}
    b_{11} & b_{12}  &\cdots & b_{1n}\\
    b_{21} & b_{22}  &\cdots & b_{2n}\\
    \vdots & \vdots &       & \vdots\\
    b_{k1}  & b_{k2} &\cdots & b_{kn}
  \end{bmatrix},
\end{align*}
to obtain a matrix with dimensions $n\times m$, and the component
$c_{ij}$, row $i$, column $j$, is exactly
\begin{equation}
  c_{ij} = \sum_{k=1}^{k}a_{ik}b_{kj}
\end{equation}

There are many ways to think about this.  One way is that we
\emph{multiply} the rows of $A$ by the columns of $B$.  Another way to
think about it is that each $c_{ij}$ is the dot product of two
vectors, the i'th row vector from $A$ with the j'th column vector of
$B$.  The dot product of two vectors having the same dimension is:
\begin{equation}
  \cvec{a_1\\a_2\\\vdots\\a_n} \cdot   \cvec{b_1\\b_2\\\vdots\\b_n} = \sum_{k=1}^{n} a_kb_k\,.
\end{equation}


There is an identity matrix for multiplication provided the matrices in question are square.
The identity matrix is denoted $I$
\begin{equation}
  I = \begin{bmatrix}
 1 & 0 & 0 & \cdots &  0 \\
 0 & 1 & 0 & \cdots &  0 \\
 0 & 0 & 1 & \cdots &  0 \\
 \vdots & \vdots & \vdots & \ddots &  \vdots  \\
 0 & 0 &  0     & \cdots     &    1
\end{bmatrix}
\end{equation}

For any square matrix $A$, we have $I\times A = A\times I = A$.

\section{Determinant}
We will present a method to compute the \emph{determinant} of a square
matrix, called the \emph{Laplacian expansion} method.

The determinant of a matrix which tells us whether the matrix has an
inverse.  Some square matrices have an inverse and some do not.  If
$\det\jparen{A}\ne 0$, then there exists a matrix, which we denote
$A^{-1}$, for which $A\times A^{-1} = A^{-1}A = I$.  The inverse of a
matrix is compute intensive to calculate. In Chapter 3
we will begin talking about ways of computing the inverse.

Given an $n\times m$ matrix:
\begin{equation}
  A = \begin{bmatrix}
    a_{11}&a_{12}&\cdots&a_{1m}\\
    a_{21}&a_{22}&\cdots&a_{2m}\\
    \vdots & \vdots &\ddots&\vdots\\
    a_{n1}&a_{n2}&\cdots&a_{nm}
  \end{bmatrix}\,,
\end{equation}
we first define $\supress{A}{i,j}$ as the $(n-1) \times (m-1)$ matrix
formed by supressing the i'th row and j'th column of $A$.


\begin{definition}[determinant]\label{def.determinant}
We may define the determinant of a square, $n\times n$  matrix as:
\begin{equation}
  \det\jparen{A} = \begin{cases}
    a_{11} & \text{if } n = 1\\
    \sum\limits_{k=1}^{n}(-1)^k a_{1k} \det\jparen{\supress{A}{1,k}} & \text{if } n > 1
    \end{cases}
\end{equation}

We may also denote $\det\jparen{A}$ as $\abs{A}$.
\end{definition}


\end{document}

1 Answer 1

0

Page breaking problem

I don't know if this answer is what you are looking for. The post you linked has a followup question here, where the OP wanted a solution to the problem without using the nocut option.

As suggested there, I think you should use tcolorbox rather than thmbox, as his breaking algorithm is more sophisticated.

By replacing the lines:

\usepackage{thmbox}

\newtheorem[bodystyle=\normalfont\noindent]{theorem}{Theorem}[section]
\newtheorem[bodystyle=\normalfont\noindent]{definition}[theorem]{Definition}

With the following code:

\usepackage[most]{tcolorbox}

\newlength{\thmboxvlineindent}
\setlength{\thmboxvlineindent}{\dimexpr21.14975pt-0.4em-0.3pt}

\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries,
        fontupper=\normalfont,
        top=0mm,
        bottom=0mm,
        right=0mm,
        left=\dimexpr\thmboxvlineindent-0.3pt,
        boxsep=0.4em,
        colback=white,
        colframe=white,
        colbacktitle=white,
        coltitle=black,
        attach boxed title to top left,
        boxed title style={empty, size=minimal, bottom=2.5pt},
        before upper={\parindent=21.14975pt\noindent},
        left skip=\parskip,
        overlay unbroken ={
            \draw[line width=0.6pt] (title.south west)--(title.south east);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west)--++(0:0.3pt);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.south west)--++(0:1cm);},
        overlay first={
            \draw[line width=0.6pt] (title.south west)--(title.south east); 
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west);},
        overlay middle={
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west);},
        overlay last={
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west)--++(0:0.3pt);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.south west)--++(0:1cm);}
    }
}

\newcounter{theorem}[section]
\renewcommand*\thetheorem{\thesection.\arabic{theorem}}
\newtcbtheorem[number within=section]
{thm}
{Theorem \thetheorem}
{thmbox,description font=\itshape,description delimiters={{\normalfont\bfseries(}}{\normalfont\bfseries)},separator sign none}{}
\newtcbtheorem[use counter from=thm]
{defn}
{Definition \thetheorem}
{thmbox,description font=\itshape,description delimiters={{\normalfont\bfseries(}}{\normalfont\bfseries)},separator sign none}{}


\newenvironment{theorem}[1][]{\refstepcounter{theorem}\csname thm*\endcsname{#1}{}}{\endthm}
\newenvironment{definition}[1][]{\refstepcounter{theorem}\csname defn*\endcsname{#1}{}}{\enddefn}

You should be able to use you theorems environment with the same syntax inside the document body.

The code is based on this answer, but should have the same dimensions (same line thickness, same margins etc.) and same title format as your original theorems.

Another solution

You can also use tcolorbox's for the theorem environment. The syntax of starting a theorem is \begin{<env name>}{<theorems title>}{label}. Although these are mandatory arguments, they can be left empty.

The last argument of the decleration of tcbtheorem defines a prefix to the label of the theorem. In the following code i will add a def. prefix to labels of definition environment, (also the dot will be automatic). with this code the definition in your example should be started with \begin{definition}{determinant}{determinant}, and to reference it you should use \ref{def.determinant}.

\usepackage[most]{tcolorbox}

\newlength{\thmboxvlineindent}
\setlength{\thmboxvlineindent}{\dimexpr21.14975pt-0.4em-0.3pt}

\tcbset{
    thmbox/.style={
        enhanced,
        breakable,
        sharp corners=all,
        fonttitle=\bfseries,
        fontupper=\normalfont,
        top=0mm,
        bottom=0mm,
        right=0mm,
        left=\dimexpr\thmboxvlineindent-0.3pt,
        boxsep=0.4em,
        colback=white,
        colframe=white,
        colbacktitle=white,
        coltitle=black,
        attach boxed title to top left,
        boxed title style={empty, size=minimal, bottom=2.5pt},
        before upper={\parindent=21.14975pt\noindent},
        left skip=\parskip,
        overlay unbroken ={
            \draw[line width=0.6pt] (title.south west)--(title.south east);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west)--++(0:0.3pt);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.south west)--++(0:1cm);},
        overlay first={
            \draw[line width=0.6pt] (title.south west)--(title.south east); 
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west);},
        overlay middle={
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west);},
        overlay last={
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.north west)--([xshift=\thmboxvlineindent]frame.south west)--++(0:0.3pt);
            \draw[line width=0.6pt] ([xshift=\thmboxvlineindent]frame.south west)--++(0:1cm);}
    }
}

\newtcbtheorem[number within=section]
{theorem}
{Theorem}
{thmbox,description font=\itshape,description delimiters={{\normalfont\bfseries(}}{\normalfont\bfseries)},separator sign none,label separator=.}{theo} % the last argument here, i.e. "theo", is the prefix for the label.
\newtcbtheorem[use counter from=theorem]
{definition}
{Definition}
{thmbox,description font=\itshape,description delimiters={{\normalfont\bfseries(}}{\normalfont\bfseries)},separator sign none,label separator=.}{def}

Equation outside of theorem box

Generally TeX does not break display math equation, so it is not a problem with extreport. If you want to write wide display math equation you should use for example the align environment provided by amsmath package.

4
  • @Uti Fogiel Are you sure the numbering works for the LaTeX code you've included above. I get that the theorems and definitions display their numbers correctly; however in text \ref{mylabel} always renders as the section number, rather than as the definition, or theorem number. Do I need to create a mwe to demonstrate?
    – Jim Newton
    Commented Dec 22, 2022 at 18:22
  • 1
    @JimNewton, I've fixed the problem in my code. I also added another suggestion (the code is similar, but you might find the syntax to be simpler).
    – Udi Fogiel
    Commented Dec 22, 2022 at 23:22
  • 1
    note that with the second solution you cant label your theorems with \label and should only use the theorem argument to do so.
    – Udi Fogiel
    Commented Dec 23, 2022 at 0:15
  • I've experimented a bit with your solution and it seems to work. Many thanks for your contribution.
    – Jim Newton
    Commented Dec 23, 2022 at 13:30

You must log in to answer this question.

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