将标题改为小写,但不在目录中

将标题改为小写,但不在目录中

我希望论文致谢页的标题采用小写字母。但是,如果我更改它,目录中的标题也会更改。 目录

我该如何避免这种情况?特别是,目录中的罗马页码也是小写字母,即使在页面上是普通小写字母。我希望让致谢条目看起来与摘要条目相同。这里有一个最简单的例子:

\documentclass[a4paper, titlepage]{article} 

\let\stdsection\section 
\renewcommand\section{\newpage\stdsection}

\begin{document}

\pagenumbering{roman}

\setcounter{secnumdepth}{0}

\begin{center}
\section{\sc{Acknowledgements}} 
Thanks
\end{center}

\section{Abstract} 
Abstract text

\tableofcontents

\cleardoublepage
\setcounter{page}{1}
\pagenumbering{arabic}

\section{Introduction}
Blablabla

\end{document}

答案1

\titleformat*(来自titlesec包)可以在文档主体中使用;使用分组机制,您可以将效果保持在本地。在下面的示例中,我将格式定义包装在命令中,使用组来修改仅所需部分单元的方面:

\documentclass[a4paper, titlepage]{article} 
\usepackage{titlesec}

\setcounter{secnumdepth}{0}

\newcommand\SpSection{%
  \titleformat*{\section}{\centering\scshape\Large}
}

\begin{document}

\pagenumbering{roman}

\begingroup
\SpSection
\section{Acknowledgements}
Thanks
\endgroup

\section{Abstract} 
Abstract text

\tableofcontents

\end{document}

在此处输入图片描述

答案2

对于这个简单的需求,该sectsty包很有用:

\documentclass[a4paper, titlepage]{article}
\usepackage{sectsty}
\newcommand\specialsection[2][\bfseries]{%
  \sectionfont{\normalfont#1}\section*{#2}
  \addcontentsline{toc}{section}{#2}
  \sectionfont{}}

\begin{document}

\pagenumbering{roman}

\specialsection[\centering\scshape]{Acknowledgements}
Thanks

\specialsection{Abstract}
Abstract text

\tableofcontents

\cleardoublepage

\pagenumbering{arabic}

\section{Introduction}
Blablabla

\end{document}

答案3

如果您想要更多的控制权,则需要定义自己的宏。要定义分段命令,您可以使用:

\newcommand\prematter@sp[1]{% 
    %\refstepcounter{section}% we do not need to step up the counter
    \addcontentsline{toc}{section}% generate toe entry
     {\protect\numberline{}\textsc{#1}}%
     \sectionmark{#1}% % add to running header
     {\clearpage\LARGE\centering\bfseries \MakeUppercase{#1}\par}%
     \@afterheading % prepare indentation handling
     \addvspace{\baselineskip}
     \@afterindentfalse % comment out if you want to indent first paragraph
  }

那么最好定义一个名为的环境\prematter

\newenvironment{prematter}[1]{%
   \prematter@sp{#1}}
{}

以下是完整的 MWE,

\documentclass[a4paper, titlepage]{book} 
\usepackage{lipsum}
\makeatletter
\newcommand\prematter@sp[1]{% % Complex form:
%\refstepcounter{section}% % step counter/ set label
\addcontentsline{toc}{section}% % generate toe entry
{\protect\numberline{}\textsc{#1}}%
\sectionmark{#1}% % add to running header
{\clearpage\LARGE\centering\bfseries \MakeUppercase{#1}\par}%
\@afterheading % prepare indentation handling
\addvspace{\baselineskip}
}
\newenvironment{prematter}[1]%
{%
   \prematter@sp{#1}}
{}
\makeatother
\begin{document}
\setcounter{secnumdepth}{0}
\frontmatter
\begin{prematter}{Acknowledgements}
\lipsum[1]
\end{prematter}
\begin{prematter}{Abstract} 
\lipsum[1]
\end{prematter}
\tableofcontents
\end{document}

答案4

扩展 Gonzalo Medina 的解决方案:

\documentclass[a4paper, titlepage]{article}
\usepackage{titlesec}
\usepackage{ltxkeys}
\makeatletter
\ltxkeys@declarekeys[KV]{spsection}[sps@]{%
  cmd/code before;
  cmd/code after;
  cmd/heading properties;
  cmd/heading type/section;
  cmd/heading text;
  bool/no heading no/true;
  cmd/label//
    \ifltxkeys@dec\else
      \ifx\\#1\\\@latexerr{Label can't be empty}\@ehd\fi
    \fi;

}
\robust@def*\spsection{\@testopt\@spsection{}}
\new@def\@spsection[#1]{%
  \saverestoresecnumdepth0%
  \usename{sps@no heading nofalse}%
  \ltxkeys@setkeys[KV]{spsection}{#1}%
  \csname sps@code before\endcsname
  \begingroup
  \ifboolFT{sps@no heading no}{}{%
    \setcounter{secnumdepth}{0}%
  }%
  \cptexpandsecond{\titleformat*}{%
    {\expandafter\expandafter\expandafter\expandafter
    \expandafter\expandafter\expandafter\noexpand
    \expandafter\expandafter\expandafter
      \csname\csname sps@heading type\endcsname\endcsname
    }{\expandcsnonce{sps@heading properties}}%
  }%
  \ifcsnnullFT{sps@heading text}{}{%
    \@@warning{Heading text was empty when calling \string\spsection}%
  }%
  \cptexpanded{\noexpand\usename{\expandcsnonce{sps@heading type}}%
    {\expandcsnonce{sps@heading text}}}%
  \endgroup
  \ifx\sps@label\@empty\else
    \label{\sps@label}%
  \fi
  \saverestoresecnumdepth{1}%
  \futurelet\next\doendcode@a
}
\robust@def*\doendcode@a{%
  \ifx\next\@sptoken
    \expandafter\doendcode@b
  \else
    \csname sps@code after\expandafter\endcsname
  \fi
}
\lowercase{\def\doendcode@b} {\usename{sps@code after}}
\robust@def*\saverestoresecnumdepth#1{%
  \ifcase#1\relax
    \edef\savedsecnumdepth{\the\c@secnumdepth}%
  \or
    \c@secnumdepth\savedsecnumdepth\relax
  \fi
}
\makeatother

% Tests
\begin{document}
\paperheight=5cm
\pagenumbering{roman}

\spsection[
  label              =sec:first,
  heading type       =section,
  heading text       =Acknowledgment,
  heading properties =\centering\scshape\Large,
  no heading no      =true,
  code before        =\noindent Last section is~\ref{sec:last}
                        on page~\pageref{sec:last}.,
  code after         =\noindent,
]
Thanks

\section{Abstract}
Abstract text.

\tableofcontents
\newpage

\pagenumbering{arabic}
\section{Test section}
Some text.
\newpage

\section{Another test section}
Some text.

\spsection[
  heading type       =subsection,
  heading text       =Test subsection,
  heading properties =\scshape\large,
  code before        =\endgraf\noindent First section is
                        on page~\pageref{sec:first}.,
  label              =sec:last
]

Some text.
\end{document} 

相关内容