amsart宏包,重定义section问题。

发布于 2023-04-11 10:59:39

各位大佬,最近在使用amsart宏包,想实现如下功能。
image.png
想让section和subsection样式一样。
我使用了titlesec宏包,

\titleformat*{\section}{\large\bfseries}{\thesection.\quad}{0pt}{}{}

image.png

确实字体和大小满足了,但是 节序号和标题之间的缩紧,无论我怎么设置label都没用。很奇怪。

还有一个问题是,“abstract”如何加粗呢?
image.png

我在amsclass.dtx中找到了

\newenvironment{abstract}{%
  \ifx\maketitle\relax
    \ClassWarning{\@classname}{Abstract should precede
      \protect\maketitle\space in AMS document classes; reported}%
  \fi
  \global\setbox\abstractbox=\vtop \bgroup
    \normalfont\Small
    \list{}{\labelwidth\z@
      \leftmargin3pc \rightmargin\leftmargin
      \listparindent\normalparindent \itemindent\z@
      \parsep\z@ \@plus\p@
%    \end{macrocode}
%    In order to get equation numbers indented with the rest of the
%    abstract, we have to do this:
%    \begin{macrocode}
      \let\fullwidthdisplay\relax
    }%
    \item[\hskip\labelsep\scshape\abstractname.]%
}{%
  \endlist\egroup
%    \end{macrocode}
%    If the abstract was supposed to be typeset earlier, then
%    \cs{@setabstract} is now equal to \cs{relax}, and we had better
%    drop the contents of the abstract box onto the page immediately, to
%    salvage the situation as best we can.
%    \begin{macrocode}
  \ifx\@setabstract\relax \@setabstracta \fi
}

感谢各位前辈抽出宝贵时间指点,附件为MWE
mwe.zip

查看更多

关注者
0
被浏览
1.3k
雾月
雾月 2023-04-13
这家伙很懒,什么也没写!

titlesec 目前可能并不兼容 AMS 文档类:https://tex.stackexchange.com/questions/543478/

如果只是想改一下 \section 的字体,可以在导言区加上:

\makeatletter
% \def\contentsnamefont{\bfseries} % 如果要改Contents
\def\section{\@startsection{section}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\large\bfseries\centering}}
\makeatother

想把 Abstract 加粗,只要把你贴出的那段代码

\item[\hskip\labelsep\scshape\abstractname.]

里的 \scshape 改成 \bfseries 即可。最好在导言区重定义 abstract 环境,而不修改 amsart.cls 文件。

另外,如果要查看某个文档类里的某个命令或环境的定义,.dtx 文件不是最好的选择,它可能包含无关代码,查看对应的 .cls 文件即可。

2 个回答
Poet
Poet 2023-04-13
这家伙很懒,什么也没写!

补充一下后续,在@雾月大佬的帮助下,成功解决。另外我修改了目录,参考了(https://tex.stackexchange.com/questions/322268/table-of-contents-amsart

最终效果:
image.png

修改后的mwe见附件。

modifiedmwe.zip

具体修改的代码如下

\makeatletter

\def\contentsnamefont{\bfseries} % 如果要改Contents
\def\section{\@startsection{section}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont\large\bfseries\centering}}
\def\subsubsection{\@startsection{subsubsection}{1}%
  \z@{.7\linespacing\@plus\linespacing}{.5\linespacing}%
  {\normalfont}}
\renewenvironment{abstract}{%
  \ifx\maketitle\relax
    \ClassWarning{\@classname}{Abstract should precede
      \protect\maketitle\space in AMS document classes; reported}%
  \fi
  \global\setbox\abstractbox=\vtop \bgroup
    \normalfont\Small
    \list{}{\labelwidth\z@
      \leftmargin3pc \rightmargin\leftmargin
      \listparindent\normalparindent \itemindent\z@
      \parsep\z@ \@plus\p@
      \let\fullwidthdisplay\relax
    }%
    \item[\hskip\labelsep\bfseries\abstractname.]%
}{%
  \endlist\egroup
  \ifx\@setabstract\relax \@setabstracta \fi
}
\def\@setabstract{\@setabstracta \global\let\@setabstract\relax}
\def\@setabstracta{%
  \ifvoid\abstractbox
  \else
    \skip@20\p@ \advance\skip@-\lastskip
    \advance\skip@-\baselineskip \vskip\skip@
    \box\abstractbox
    \prevdepth\z@ % because \abstractbox is a vtop
  \fi
}

\renewcommand\contentsnamefont{\Large\bfseries}

%Table of Contents
\setcounter{tocdepth}{3}

% Add bold to \section titles in ToC and remove . after numbers
\renewcommand{\tocsection}[3]{%
  \indentlabel{\@ifnotempty{#2}{\bfseries\ignorespaces#1 #2\quad}}\bfseries#3}
% Remove . after numbers in \subsection
\renewcommand{\tocsubsection}[3]{%
  \indentlabel{\@ifnotempty{#2}{\ignorespaces#1 #2\quad}}#3}
%\let\tocsubsubsection\tocsubsection% Update for \subsubsection
%...

\newcommand\@dotsep{4.5}
\def\@tocline#1#2#3#4#5#6#7{\relax
  \ifnum #1>\c@tocdepth % then omit
  \else
    \par \addpenalty\@secpenalty\addvspace{#2}%
    \begingroup \hyphenpenalty\@M
    \@ifempty{#4}{%
      \@tempdima\csname r@tocindent\number#1\endcsname\relax
    }{%
      \@tempdima#4\relax
    }%
    \parindent\z@ \leftskip#3\relax \advance\leftskip\@tempdima\relax
    \rightskip\@pnumwidth plus1em \parfillskip-\@pnumwidth
    #5\leavevmode\hskip-\@tempdima{#6}\nobreak
    \leaders\hbox{$\m@th\mkern \@dotsep mu\hbox{.}\mkern \@dotsep mu$}\hfill
    \nobreak
    \hbox to\@pnumwidth{\@tocpagenum{\ifnum#1=1\bfseries\fi#7}}\par% <-- \bfseries for \section page
    \nobreak
    \endgroup
  \fi}
\AtBeginDocument{%
\expandafter\renewcommand\csname r@tocindent0\endcsname{0pt}
}
\def\l@subsection{\@tocline{2}{0pt}{2.5pc}{5pc}{}}
\def\l@subsubsection{\@tocline{2}{0pt}{4pc}{5pc}{}}

\makeatother

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览