# Centering ornaments from pgfornaments around a theorem environment?

Here is my minimal code:

\documentclass[12pt,letterpaper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{pgfornament}

\newtheorem{thm}{Theorem}

\newcommand*{\centeredornament}{\begin{center}\pgfornament{88}\end{center}}
\newenvironment{theorem}[1][]{\centeredornament\begin{thm}[#1]\upshape}{\end{thm}\centeredornament}

\begin{document}
\begin{theorem}[This is a sentence. ]
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
\end{theorem}

\end{document}


It produces the following as output:

The black portions mark the width of the page. See how the ornaments are shifted to the right, rather than actually being "centered" on the page width? How can I fix this?

You should add option [width=13cm] to your used command \pgfornament like

\pgfornament[width=13cm]{88}


Without this width the ornament is to long to fit into the textwidth of your text.

You can use

\usepackage{showframe}


to visualize the typing area and margins.

With the complete MWE

\documentclass[12pt,letterpaper]{article}

\usepackage{showframe} % <==============================================
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{pgfornament}

\newtheorem{thm}{Theorem}

\newcommand*{\centeredornament}{\begin{center}\pgfornament[width=13cm]{88}\end{center}} % 88
\newenvironment{theorem}[1][]{\centeredornament\begin{thm}[#1]\upshape}{\end{thm}\centeredornament}

\begin{document}
\begin{theorem}[This is a sentence. ]
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence. This is a sentence. This is a sentence.
This is a sentence. This is a sentence. This is a sentence. This is a
sentence. This is a sentence.
\end{theorem}

\end{document}


you get this result:

Without [width=13cm] you get the following result (see the ornament line reaching the margin):

Your ornaments are actually stretching beyond the margins, as the overfull vbox warnings your code issues, tell you.

So, you could set things up better with a \makebox also taking care of indent with:

\newcommand*{\centeredornament}{\noindent\makebox[\textwidth][c]{\pgfornament[width=1.1\textwidth]{88}}}


The [width=1.1\textwidth] for the ornament is there to deliberately have it a little larger than textwidth (but centered), as it seems to be your intent. But you can set this value as you please, of course.

In full:

\documentclass[12pt,letterpaper]{article}

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{pgfornament}
\usepackage{showframe}

\newtheorem{thm}{Theorem}

\newcommand*{\centeredornament}{\noindent\makebox[\textwidth][c]{\pgfornament[width=1.1\textwidth]{88}}}

\newenvironment{theorem}[1][]{\centeredornament\begin{thm}[#1]\upshape}{\end{thm}\vspace{-1ex}\centeredornament}

\begin{document}

\begin{theorem}[This is a sentence. ]
This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence. This is a sentence.
\end{theorem}

\end{document}