这是我的最小代码:
\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}
它产生以下输出:
黑色部分标记了页面的宽度。看到装饰物向右移动了吗,而不是实际上位于页面宽度的“中心”吗?我该如何解决这个问题?
答案1
您应该[width=13cm]
向使用的命令添加选项\pgfornament
,例如
\pgfornament[width=13cm]{88}
如果没有这个宽度,装饰物就会太长而无法适合文本的宽度。
您可以使用
\usepackage{showframe}
使打字区域和边距可视化。
拥有完整的 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}
你会得到这个结果:
如果没有的话,[width=13cm]
你会得到以下结果(参见到达边缘的装饰线):
答案2
您的装饰品实际上已经超出了边缘,正如代码问题中发出的过满 vbox 警告所告诉您的那样。
因此,您可以使用以下方法更好地设置缩进\makebox
:
\newcommand*{\centeredornament}{\noindent\makebox[\textwidth][c]{\pgfornament[width=1.1\textwidth]{88}}}
装饰物的宽度[width=1.1\textwidth]
故意比文本宽度稍大(但居中),这似乎是您的意图。当然,您可以随意设置此值。
在全:
\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}