基于回答我之前的一个问题,我实现了以下代码,该代码应该在我的文档的边缘离散地枚举示例:
\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,geometry,graphicx,amstext}
\usepackage[amsmath]{ntheorem}
% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
{\item[\theorem@headerfont \llap{##1 ##2}]}%
{\item[\theorem@headerfont \llap{##1 ##2}| ##3\theorem@separator\hskip\labelsep]}%
\makeatother
% my example
\theoremstyle{mymargin}
\newtheorem{example}{Example}
\numberwithin{example}{chapter}
\begin{document}
\begin{example}
\centering
\begin{tabular}{cccc}
this & is & a & test\\
table & where & text & goes
\end{tabular}
\end{example}
\end{document}
这将产生以下输出:
如你所见,由于表格居中,示例数字实际上不是在边缘,这是我最关心的问题。此外,我希望数字与表格顶部对齐,并始终与表格位于同一页(情况也并非总是如此)。最后,当启用双页选项时,我希望数字始终出现在外边距中。如何修复此问题?
答案1
\centering
在这里有点太多了,如果有以下文本则不合适。使用\begin{center}...\end{center]
带有前缀的转义符\leavevmode
:
\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb,geometry,graphicx,amstext}
\usepackage[amsmath]{ntheorem}
% margin theorem
\makeatletter
\newtheoremstyle{mymargin}%
{\item[\theorem@headerfont \llap{##1 ##2}]}%
{\item[\theorem@headerfont \llap{##1 ##2}| ##3\theorem@separator\hskip\labelsep]}%
\makeatother
% my example
\theoremstyle{mymargin}
\newtheorem{example}{Example}
\numberwithin{example}{chapter}
\begin{document}
\begin{example}
Ordinary example.
\end{example}
\begin{example}
\leavevmode\begin{center}
\begin{tabular}{cccc}
this & is & a & test\\
table & where & text & goes
\end{tabular}
\end{center}
And now comes the discussion of the rest of the example.
\end{example}
\begin{example}
\begin{equation*}
x=y
\end{equation*}
\end{example}
\end{document}