抽象环境改变页码

抽象环境改变页码

我正在使用文档类撰写论文book

为了包含致谢环境,我在代码中添加了几行。

现在的问题是,使用这个致谢环境会重置页码,出于某种我不明白的原因。

另外,我无法包含抽象环境。有人可以帮忙吗?

\documentclass[12pt, a4paper]{book}

\makeatletter
\newcommand\ackname{\Large Acknowledgments}
 \if@titlepage
 \newenvironment{acknowledgments}{%
   \titlepage
   \null\vfil
   \@beginparpenalty\@lowpenalty
   \begin{center}%
     \bfseries \ackname
     \@endparpenalty\@M
   \end{center}}%
  {\par\vfil\null\endtitlepage}
\else
\newenvironment{acknowledgments}{%
   \if@twocolumn
     \section*{\abstractname}%
   \else
     \small
     \begin{center}%
       {\bfseries \ackname\vspace{-.5em}\vspace{\z@}}%
     \end{center}%
     \quotation
   \fi}
   {\if@twocolumn\else\endquotation\fi}
\fi
\makeatother

\begin{document}
\begin{titlepage}
 \centering   
\begin{center}
{\Huge This the title}
   \end{center}
 \end{titlepage}

 \begin{acknowledgments}
 These are the acknowledgments
 \end{acknowledgments}

 \tableofcontents
 \chapter{First chapter}
 \end{document}

答案1

@egreg 回答时我正在慢慢准备下面的代码,它完全按照你试图做的事情去做,也就是说,将致谢排版为摘要,但不重置页码。此代码遵守titlepage/notitlepage选项以及onecolumn/twocolumn选项。

\documentclass[12pt,a4paper]{book}

\makeatletter

\newcommand*\ackname{Acknowledgments}
\if@titlepage
  \newenvironment*{acknowledgments}{%
    \cleardoublepage
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse\newpage
    \fi
    \thispagestyle{empty}%
    \null\vfil
    \@beginparpenalty\@lowpenalty
    \begin{center}%
      \Large \bfseries \ackname
      \@endparpenalty\@M
    \end{center}%
  }{%
    \par\vfil\null  % the standard classes do so, but is it right?
    \endtitlepage   % this can be safely used
  }
\else
\newenvironment{acknowledgments}{%
   \if@twocolumn
     \section*{\ackname}%
   \else
     \small
     \begin{center}%
       {\bfseries \ackname\vspace{-.5em}\vspace{\z@}}%
     \end{center}%
     \quotation
   \fi}
   {\if@twocolumn\else\endquotation\fi}
\fi
\makeatother

\begin{document}
\begin{titlepage}
 \centering   
\begin{center}
{\Huge This the title}
   \end{center}
 \end{titlepage}

 \begin{acknowledgments}
 These are the acknowledgments
 \end{acknowledgments}

 \tableofcontents
 \chapter{First chapter}
 \end{document}

不过,让我澄清一下,我并不认可或推荐这种解决方案。

答案2

定义环境没有 \titlepage

\documentclass[12pt, a4paper]{book}

\newcommand\ackname{Acknowledgments}
\newenvironment{acknowledgments}
 {%
  \cleardoublepage
  \thispagestyle{plain}
  \addcontentsline{toc}{chapter}{\ackname}
  \vspace*{\fill}
  \begin{center}
  \bfseries\Large\ackname
  \end{center}
 }
 {\par\vspace*{\fill}}

\begin{document}

\begin{titlepage}
\begin{center}
\Huge This the title
\end{center}
\end{titlepage}

\begin{acknowledgments}
These are the acknowledgments
\end{acknowledgments}

\tableofcontents

\chapter{First chapter}

\end{document}

说实话,我更喜欢更简单的

\chapter*{\ackname}
\addcontentsline{toc}{chapter}{\ackname}

These are the acknowledgments

相关内容