# The problem with box at the end of example

I have to be at the end of each example, sign the box. However, in various situations, it appears in some other places. I would like that it was always in the same place. I wish that was on the right side in the last line. As in the first example. I do not want to was lower as in the example of the second and third. When the example ends the text is well. However, when the ends using array or equation is below. I do not know how to change it. It is very important to me.

It is my code:

\documentclass[12pt,a4paper,twoside]{book}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm, amssymb}
\usepackage[polish]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{latexsym}
\usepackage[nottoc]{tocbibind}
\usepackage{graphicx}
\usepackage{fancyhdr}
\usepackage{indentfirst}
\usepackage{dsfont}
\usepackage{stackrel}
\usepackage{etoolbox}
\usepackage{listingsutf8}
\usepackage{ucs}
\usepackage{url}

\textwidth 15.3cm
\textheight 22.2cm
\topmargin 0cm
\oddsidemargin 0.55cm
\evensidemargin 0cm

\fancypagestyle{number}{
\lfoot{}
\cfoot{\thepage}
\rfoot{}
\renewcommand{\footrulewidth}{0pt}
}

\newtheoremstyle{stylexample}% name
{}%      Space above, empty = usual value'
{}%      Space below
{\normalfont}% Body font e.g. \normalfont \bfseries \itshape
{}%         Indent amount (empty = no indent, \parindent = para indent)
{\newline}% Space after thm head: \newline = linebreak

\newtheorem{example}[chapter]{Example}
\AtEndEnvironment{example}{\null\hfill\qedsymbol}

\begin{document}
\thispagestyle{number}\chapter{Number}

\begin{example}
During the 19th century, mathematicians began to develop many different abstractions which share certain properties of numbers and may be seen as extending the concept. Among the first were the hypercomplex numbers, which consist of various extensions or modifications of the complex number system. Today, number systems are considered important special examples of much more general categories such as rings and fields, and the application of the term "number" is a matter of convention, without fundamental significance.
\end{example}

\begin{example}
$$\begin{array}{c} abc:\\ a \\ b \\ c .\\ \end{array}$$\end{example}

\begin{example}
$$\nonumber 2+3=5$$
\end{example}

\end{document}

• You should use \qedhere. – Matsmath Jun 2 '16 at 15:45
• Welcome to TeX.SX! A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "{}" on it). By the way, you can have a look there to know more about minimal working example (MWE) (-; – ebosi Jun 2 '16 at 15:47
• Using ntheorem instead of amsthm, this would be automatic. Comment aside; don't use $$…$$, which plain TeX code for displayed equations. Replace it with $…$. – Bernard Jun 2 '16 at 16:03
• That is how it is when you use amsthm, you could switch to ntheorem, and use its thmmarks option, then it can place it like you want. There is a price to pay of course, no blank lines before end example, plus it may take a few compilations before the marker settles – daleif Jun 2 '16 at 16:04
• I add \qedhere but i don't see box – user107084 Jun 2 '16 at 16:07

The way to fix this is to use \qedhere at the end of the last line of math, before you close any environment such as array or align.
\begin{example}
$\begin{array}{c} abc:\\ a \\ b \\ c. \qedhere % <-- here \end{array}$
`