为什么 abntex2 类在章节标题后插入新行?

为什么 abntex2 类在章节标题后插入新行?

我正在使用这个定制如何在每个部分自动添加[转至摘要] | [返回]?但是当我将它与abntex2类一起加载时,我的返回按钮被放在命令的下一行。对于其他所有\chapter{}功能,一切正常:\section{}

在此处输入图片描述

如果我从类中删除以下代码abntex2,那么它就被修复了:

https://github.com/abntex/abntex2/blob/15a981c300198ca59920eea17f02893490adf878/tex/latex/abntex2/abntex2.cls#L603-L614

  \def\printchaptertitle##1{%
    \chaptitlefont%
    \ifthenelse{\boolean{abntex@innonumchapter}}{\centering\ABNTEXchapterupperifneeded{##1}}{%
    \ifthenelse{\boolean{abntex@apendiceousecao}}{%
        \centering%
        \settowidth{\chapternamenumlength}{\printchaptername\printchapternum\afterchapternum}%
        \ABNTEXchapterupperifneeded{##1}%
      }{%
        \settowidth{\chapternamenumlength}{\printchaptername\printchapternum\afterchapternum}%
        \parbox[t]{\columnwidth-\chapternamenumlength}{\ABNTEXchapterupperifneeded{##1}}}%
     }
  }

在此处输入图片描述


这是我的最小例子:

\documentclass[
10pt,
a5paper
]{abntex2}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{amssymb}
\newcommand{\goToSummaryText}
{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}
\makeatletter
    \newif\ifismemoirloaded\ismemoirloadedfalse
    \@ifclassloaded{memoir}
    {%
        \ismemoirloadedtrue
    }{}
    \newcommand{\addGoToSummary}
    {%
        \renewcommand{\Sectionformat}[2]{##1 \protect\goToSummaryText}
        \ifismemoirloaded
            \let\oldprintchaptertitle\printchaptertitle
            \renewcommand{\printchaptertitle}[1]{\oldprintchaptertitle{##1} \protect\goToSummaryText}
        \else\fi
    }
    \newcommand{\removeGoToSummary}
    {%
        \renewcommand{\Sectionformat}[2]{##1}
        \ifismemoirloaded
            \let\printchaptertitle\oldprintchaptertitle
        \else\fi
    }
\makeatother
\let\oldtableofcontents\tableofcontents
\renewcommand{\tableofcontents}
{%
    \hypertarget{summary}%
    \oldtableofcontents%
}

\begin{document}
    \addGoToSummary
    \chapter{Section contents}
    thing2.
\end{document}

我该如何修补abntex2类或我的命令来解决这个问题?

参考:

  1. 回忆录类中的“\Sectionformat”与“\Chapterformat”等效的是什么?
  2. 如何修复转到摘要以便 \section[Some]{Some more} 不会抛出所有这些错误?

答案1

abntex2我设法通过检查是否已加载并直接修补来修复它\ABNTEXchapterupperifneeded

如果有人知道更好或更通用的答案,请分享!

\documentclass[
10pt,
a5paper
]{memoir}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xcolor}

\definecolor{ultramarine}{RGB}{0,32,96}
\RequirePackage{xpatch}
\RequirePackage{amssymb}
\RequirePackage{hyperref}
\newcommand{\goToSummaryText}{{%
    \small\mdseries
    \hyperlink{summary}{\textcolor{ultramarine}{$\leftleftarrows$}}
    {$|$}
    \Acrobatmenu{GoBack}{\textcolor{ultramarine}{$\leftarrow$}}
}}
\makeatletter
    \newif\ifismemoirloaded\ismemoirloadedfalse
    \newif\ifisabntexloaded\isabntexloadedfalse
    \@ifclassloaded{memoir}{%
        \ismemoirloadedtrue%
    }{}
    \@ifclassloaded{abntex2}{%
        \isabntexloadedtrue%
    }{}
    \newcommand{\addGoToSummary}
    {%
        \@ifundefined{printparttitle}{\message{printparttitle patch for addGoToSummary could NOT
                    be applied because there is no printparttitle command available!^^J}}{%
            \let\oldAddGoToprintparttitle\printparttitle
            \xapptocmd{\printparttitle}{~\protect\goToSummaryText}{}{}
        }
        \@ifundefined{Sectionformat}{\message{Sectionformat patch for addGoToSummary could NOT
                    be applied because there is no Sectionformat command available!^^J}}{%
            \let\oldAddGoToSectionformat\Sectionformat
            \xapptocmd{\Sectionformat}{~\protect\goToSummaryText}{}{}
        }
        \ifismemoirloaded
            \ifisabntexloaded
                \let\oldAddGoToABNTEXchapterupperifneeded\ABNTEXchapterupperifneeded
                \xapptocmd{\ABNTEXchapterupperifneeded}{~\protect\goToSummaryText}{}{}
            \else
                \let\oldAddGoToprintchaptertitle\printchaptertitle
                \xapptocmd{\printchaptertitle}{~\protect\goToSummaryText}{}{}
            \fi
        \else
            \@ifundefined{Chapterformat}{\message{Chapterformat patch for addGoToSummary could NOT
                        be applied because there is no Chapterformat command available!^^J}}{%
                \let\oldAddGoToChapterformat\Chapterformat
                \xapptocmd{\Chapterformat}{~\protect\goToSummaryText}{}{}
            }
        \fi
    }
    \newcommand{\removeGoToSummary}
    {%
        \@ifundefined{oldAddGoToprintparttitle}{}{\let\printparttitle\oldAddGoToprintparttitle}
        \@ifundefined{oldAddGoToSectionformat}{}{\let\Sectionformat\oldAddGoToSectionformat}
        \ifismemoirloaded
            \ifisabntexloaded
                \@ifundefined{oldAddGoToABNTEXchapterupperifneeded}{}{\let\ABNTEXchapterupperifneeded\oldAddGoToABNTEXchapterupperifneeded}
            \else
                \@ifundefined{oldAddGoToprintchaptertitle}{}{\let\printchaptertitle\oldAddGoToprintchaptertitle}
            \fi
        \else
            \@ifundefined{oldAddGoToChapterformat}{}{\let\Chapterformat\oldAddGoToChapterformat}
        \fi
    }
\makeatother
\let\oldAddGoTotableofcontents\tableofcontents
% Insert internal document link
\renewcommand{\tableofcontents}{%
    \hypertarget{summary}%
    \oldAddGoTotableofcontents%
}

\begin{document}
    \addGoToSummary
    \part{My}
    \chapter{Chapter title}
    thing1.
    \removeGoToSummary
    \section{Section title}
    thing2.
    \addGoToSummary
    \section{Section title}
    thing3.
\end{document}

参考:

  1. 为什么 abntex2 类在章节标题后插入新行?
  2. 如何在每个部分自动添加[转至摘要] | [返回]?
  3. 如何修复转到摘要以便 \section[Some]{Some more} 不会抛出所有这些错误?
  4. 回忆录类中的“\Sectionformat”与“\Chapterformat”等效的是什么?
  5. 为什么 xapptocmd 要减少 \partname 和 \parttile 之间的垂直空间?

相关内容