标题的名称应该是“Myheader”。目前我已经解决了这个问题,如下所示:
\makeatletter
\newcommand{\Myheader}{\subsubsection}
\makeatother
\titlespacing*{\subsubsection}{0cm}{0cm}{2pt}%pbk
\titleformat{\subsubsection}[display]{\Huge\filleft\scshape}{ \normalfont\bf\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}]
我仍然希望能够使用\subsubsection
标头,因此该解决方案不可接受。代码的一个最小示例是:
\documentclass[10pt,a4paper,oneside]{article}
\usepackage[danish,english]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\makeatletter
\newcommand{\Myheader}{\subsubsection}
\makeatother
\titlespacing*{\subsubsection}{0cm}{0cm}{2pt}%pbk
\titleformat{\subsubsection}[display]{\Huge\filleft\scshape}{ \normalfont\bf\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}]
\begin{document}
\Myheader{The first appendix}
\end{document}
知道如何解决这个问题吗?
答案1
您可以修补发出的开始附录的命令,以便\section
在该点之后产生正确的结果,即仅适用于附录。这将确保您的附录放置在部分层次结构中的正确级别(例如目录或书签),并使您的代码具有最大的灵活性(例如,如果您改变主意,只需删除补丁)。
例如:
\documentclass[10pt,a4paper,oneside]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{titlesec,etoolbox}
\usepackage{kantlipsum}
\apptocmd\appendix{%
\titlespacing*{\section}{0cm}{0cm}{2pt}%pbk
\titleformat{\section}[display]{\Huge\filleft\scshape}{ \normalfont\bfseries\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}]
}{\typeout{Appendices title formatting successfully patched. Expect the expected.}}{\typeout{Appendices title formatting could not be patched. Unexpected results paradoxically to be expected.}}
\begin{document}
\section{A section}
\kant[1]
\section{Another section}
\kant[2]
\appendix
\section{The first appendix}
\kant[3]
\end{document}
编辑
在评论中,您询问如何修改它以在发出\section
后获取页面上的空标题。您的评论让我假设您正在使用。如果不知道您目前在其他地方使用的标题代码,很难指定执行此操作的最佳方法,但如果您有合理的标准,这应该可行。\appendix
fancyhdr
\documentclass[10pt,a4paper,oneside]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{titlesec,etoolbox,fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyhf[lh]{\leftmark}
\fancyhf[rh]{\thepage}
\fancypagestyle{ancy}{%
\fancyhf[h]{}%
\renewcommand\headrulewidth{0pt}%
}
\usepackage{kantlipsum}
\apptocmd\appendix{%
\titlespacing*{\section}{0cm}{0cm}{2pt}%pbk
\titleformat{\section}[display]{\Huge\filleft\scshape}{ \normalfont\bfseries\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}\thispagestyle{ancy}]
}{\typeout{Appendices title formatting successfully patched. Expect the expected.}}{\typeout{Appendices title formatting could not be patched. Unexpected results paradoxically to be expected.}}
\begin{document}
\section{A section}
\kant[1-4]
\section{Another section}
\kant[5]
\appendix
\section{The first appendix}
\kant[6-8]
\end{document}
请注意,这是对您的描述的字面解释,可能就是也可能不是您想要的。特别是:
\section
以下\appendix
将清空当前页面的页眉,即使该页面\section
之前还包含\appendix
;- 以下页面
\appendix
若不包含 ,则包含标准页眉\section
。
\appendix
如果你根本不想要后面的标题。你可以使用:
\apptocmd\appendix{%
\pagestyle{ancy}%
\titlespacing*{\section}{0cm}{0cm}{2pt}%pbk
\titleformat{\section}[display]{\Huge\filleft\scshape}{ \normalfont\bfseries\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}\thispagestyle{ancy}]
}{\typeout{Appendices title formatting successfully patched. Expect the expected.}}{\typeout{Appendices title formatting could not be patched. Unexpected results paradoxically to be expected.}}
fancyhdr
这里的其他可能性更为复杂,因此我只会在必要时考虑这些可能性。在这种情况下,我将根据您当前的标头代码进行操作,因为此时最容易摆脱它。titleps
补充titlesec
并在此处运行良好。
编辑 编辑
针对您关于\tableofcontents
以类似方式进行修补的问题,您当然可以这样做。但是,我承认,我对所有内容应该是什么样子有点迷茫,我无法真正弄清楚您发布的代码的确切用途。(但明确的分页符和页码不应该包含在页面样式的定义中。)
我这样做了:
\pretocmd\tableofcontents{%
\titlespacing*{\section}{0cm}{0cm}{2pt}%pbk
\titleformat{\section}[display]{\Huge\filleft\scshape}{ \normalfont\bfseries\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thesection}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}\thispagestyle{ancy}]
}{\typeout{Contents title formatting successfully patched. Expect the expected.}}{\typeout{Contents title formatting could not be patched. Unexpected results paradoxically to be expected.}}
\apptocmd\tableofcontents{%
\titlespacing*{\section}{0pt}{*5}{*2.5}%
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{\thesection}{1.5em}{}[\thispagestyle{fancy}]
}{\typeout{Contents title formatting successfully patched again. Expect the expected.}}{\typeout{Contents title formatting could not be patched again. Unexpected results paradoxically to be expected.}}
这给了我这个
但是现在我怀疑你真的只是使用了错误的类。如果你使用book
或 ,report
那么无论如何你都会得到更多这样的内容。book
例如,使用 ,你会得到\frontmatter
, \mainmatter and
\backmatter which are starting to look suspiciously like code you are trying to create here. If so, don't reinvent the wheel - use the right tool for the job and choose
book or a
book` 之类的类。