![我怎样才能保持分段但禁用其显示](https://linux22.com/image/402765/%E6%88%91%E6%80%8E%E6%A0%B7%E6%89%8D%E8%83%BD%E4%BF%9D%E6%8C%81%E5%88%86%E6%AE%B5%E4%BD%86%E7%A6%81%E7%94%A8%E5%85%B6%E6%98%BE%E7%A4%BA.png)
我很高兴titlesec
能够titleps
跟踪章节并创建页脚,这些页脚取决于章节是否开始或继续,但一个案例无法直接获得自定义格式。因此,我希望将分节与其格式分离。作为一种解决方法,目前,我只想禁用任何排版\chapter{...}
。在下面的示例中,这意味着只删除“第 1 章\nl 字体”,这样“某些自定义章节格式”就会出现在同一页面的顶部。
\documentclass{report}
\usepackage{fontawesome}
\usepackage{lastpage}
\usepackage{tabularx}
\usepackage{titlesec}
\usepackage{titleps}
\usepackage{xparse}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewDocumentCommand{\thedoc}
{}% Is there not a command for `token list` in xparse?
{THIS DOC}
\NewDocumentCommand{\myheaderii}
{+mm}
{%
\begin{tabularx}{\textwidth}{@{}XR@{}}#1\end{tabularx}
}
\NewDocumentCommand{\myheaderiii}
{+mmm}
{%
\begin{tabularx}{\textwidth}{@{}X@{}C@{}R@{}}#1\end{tabularx}
}
\NewDocumentCommand{\chapterMark}{}{UNDEFINED!}
\NewDocumentCommand{\setchapterMark}{m}
{%
\RenewDocumentCommand{\chapterMark}{}{#1}
}
%\setcounter{chapter}{0}
\NewDocumentCommand{\newChapter}{mmO{}}
{%
% \stepcounter{chapter}
\chapter{#1}
\setchapterMark{#2}
SOME CUST CHAP. FORMAT%THAT NO EXISTING PACKAGE CAN EASILY MAKE
\textless#1\textgreater
}
% pagestyle--------------------------------------------------------
\newpagestyle{specialii}
{
\setfoot{%
\myheaderii{\thedoc}{\thepage/\pageref{LastPage}}%
}{}{}
}
\newpagestyle{specialiii}
{
\setfoot{%
\myheaderiii{\thedoc}{\chapterMark}{\thepage/\pageref{LastPage}}%
}{}{}
}
\assignpagestyle{\chapter}{specialii}
\begin{document}
\pagestyle{specialiii}
%\pagestyle{empty}
\begin{titlepage}\vspace*{\fill}\huge\begin{center}\thedoc\end{center}\vspace*{\fill}\end{titlepage}
\newChapter{Fonts}{\faFont}
Let's make that span\newpage another page
\end{document}
答案1
这里有一个建议,当然需要调整,因为有些问题需要回答:章节标题替换文本是否会成为所有此类布局的固定文本,还是只是一个没有标签的新章节标题?目录和页眉/页脚呢?
\documentclass{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a6paper, margin=20pt, bottom=34pt, footskip=24pt, showframe]{geometry}
\usepackage{fontawesome5}
\usepackage{lastpage}
\usepackage{lipsum} % Dummy Text
\usepackage[pagestyles, explicit]{titlesec}
\usepackage{xparse, etoolbox}
\usepackage{tabularx}
\usepackage{hyperref}
\renewcommand*\familydefault{\sfdefault}
\NewDocumentCommand{\chapterLabel}{}{Ch. \thechapter}
\NewDocumentCommand{\chapterMark}{}{U HAVE TO DEFINE IT!}
\NewDocumentCommand{\setchapterMark}{m}
{%
\RenewDocumentCommand{\chapterMark}{}{#1}
}%
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newpagestyle{main}{%
\setfoot{\thepage/\pageref{LastPage}}{}{\chapterLabel}
}%
\newpagestyle{special}{%
\setfoot{\thepage/\pageref{LastPage}}{}{\chapterMark}
}%
\newtoggle{nodisplay}
\titleformat{\chapter}{\thispagestyle{empty}\sffamily\large}{\iftoggle{nodisplay}{}{\rlap{\makebox[\textwidth][r]{Ch. \thechapter}}}}{0em}{\iftoggle{nodisplay}{\vspace*{-8.5ex}}{#1}}[\leavevmode\togglefalse{nodisplay}]
\titlespacing*{\chapter}{0pt}{-3ex}{4ex}%-5ex
\pagestyle{main}
\begin{document}
\title{Lorem Ipsum}
\author{Dolor S. Amet}
\maketitle
%
\chapter{Gibberish}
%
\lipsum[1-5]{
\toggletrue{nodisplay}
\chapter{More Gibberish}}
SOME CUSTOM TITLE \par
\lipsum[6-12]
\clearpage
\chapter{Still More Gibberish}
\lipsum[6-12]
\clearpage
\setchapterMark{\faBook}
\pagestyle{special}
\chapter*{Bibliography}
Let's make that
\newpage
... span a second page
\end{document}
答案2
以下是我尝试改编@Bernard 的回答以适应该帖子的 MWE:
\documentclass{report}
\usepackage{fontawesome}
\usepackage[showframe]{geometry}
\usepackage{lastpage}
\usepackage{tabularx}
\usepackage[explicit]{titlesec}
\usepackage{titleps}
\usepackage{xparse,etoolbox}
\makeatletter\def\@makechapterhead#1{}\makeatother
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewDocumentCommand{\thedoc}
{}% Is there not a command for `token list` in xparse?
{THIS DOC}
\NewDocumentCommand{\myheaderii}
{+mm}
{%
\begin{tabularx}{\textwidth}{@{}XR@{}}#1\end{tabularx}
}
\NewDocumentCommand{\myheaderiii}
{+mmm}
{%
\begin{tabularx}{\textwidth}{@{}X@{}C@{}R@{}}#1\end{tabularx}
}
\NewDocumentCommand{\chapterMark}{}{UNDEFINED!}
\NewDocumentCommand{\setchapterMark}{m}
{%
\RenewDocumentCommand{\chapterMark}{}{#1}
}
%\setcounter{chapter}{0}
\NewDocumentCommand{\newChapter}{mmO{}}
{%
\setchapterMark{#2}
\chapter{#1}
}
% pagestyle--------------------------------------------------------
\newpagestyle{specialii}
{
\setfoot{%
\myheaderii{\thedoc}{\thepage/\pageref{LastPage}}%
}{}{}
}
\newpagestyle{specialiii}
{
\setfoot{%
\myheaderiii{\thedoc}{\chapterMark}{\thepage/\pageref{LastPage}}%
}{}{}
}
\newtoggle{nodisplay}
\titleformat{\chapter}
{
\thispagestyle{specialii}
\sffamily\large
}
{
\iftoggle{nodisplay}
{}
{
}
}
{0em}
{
\iftoggle{nodisplay}
{
%\vspace*{-8.5ex}
}
{SOME CUST CHAP. FORMAT%THAT NO EXISTING PACKAGE CAN EASILY MAKE
\textless#1\textgreater}
}[\leavevmode\togglefalse{nodisplay}]
\titlespacing*{\chapter}{0pt}{-3ex}{0ex}%-5ex
\begin{document}
\pagestyle{specialiii}
\begin{titlepage}\vspace*{\fill}\huge\begin{center}\thedoc\end{center}\vspace*{\fill}\end{titlepage}
\newChapter{Fonts}{\faFont}
Let's make that span\newpage another page
\end{document}
答案3
这是一个更接近问题规范的答案,因为它禁用了章节标题的显示,仅此而已。我举了一个例子这里其中自定义章节标题titleformat
可能不可行。我添加了目录以显示它不受影响。代码中仍保留一些修饰性的 TODO...
\documentclass{report}
\usepackage[french]{babel} % added to problem specification
\usepackage{fontawesome}
\usepackage[showframe]{geometry}
\usepackage{lastpage}
\usepackage{tabularx}
\usepackage{titleps}
\usepackage{xparse}
\usepackage{xpatch}
%https://tex.stackexchange.com/questions/511253/how-can-i-keep-sectioning-but-disable-its-display
%disabling chapter display----------------------------------------
% \makeatletter\def\@makechapterhead#1{}\makeatother
% This one does:
\usepackage{xpatch}
\tracingpatches
\makeatletter % the macro name contains @
\patchcmd{\@chapter}{\if@twocolumn
\@topnewpage[\@makechapterhead{#2}]%
\else
\@makechapterhead{#2}%
\@afterheading
\fi}{}{}{}
\makeatother
%-----------------------------------------------------------------
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\NewDocumentCommand{\thisdoc}
{}% TODO Is there not a command for `token list` in xparse?
{THIS DOC}
\NewDocumentCommand{\myheaderii}
{+mm}
{%
\begin{tabularx}{\textwidth}{@{}XR@{}}#1\end{tabularx}
}
\NewDocumentCommand{\myheaderiii}
{+mmm}
{%
\begin{tabularx}{\textwidth}{@{}X@{}C@{}R@{}}#1\end{tabularx}
}
\NewDocumentCommand{\chapterMark}{}{UNDEFINED!}
\NewDocumentCommand{\setchapterMark}{m}
{%
\RenewDocumentCommand{\chapterMark}{}{#1}
}
\NewDocumentCommand{\newChapter}{mmO{}}
{%
\setchapterMark{#2}
\chapter{#1}
\thispagestyle{specialii}
{SOME CUST CHAP. FORMAT%THAT NO EXISTING PACKAGE CAN EASILY MAKE
\textless#1\textgreater}
}
%-----------------------------------------------------------------
\newpagestyle{specialii}
{
\setfoot{%
\myheaderii{\thisdoc}{\thepage/\pageref{LastPage}}%
}{}{}
}
\newpagestyle{specialiii}
{
\setfoot{%
\myheaderiii{\thisdoc}{\chapterMark}{\thepage/\pageref{LastPage}}%
}{}{}
}
\begin{document}%-------------------------------------------------
\thispagestyle{empty}
\begin{titlepage}\vspace*{\fill}\huge\begin{center}\thisdoc\end{center}\vspace*{\fill}\end{titlepage}
\tableofcontents
\pagestyle{specialiii}
\newChapter{Writing}{\faPencil}
Let's make that span\newpage another page
\newChapter{Fonts}{\faFont}
Fonts are great.
\end{document}
10/10编辑:
将 对 内部进行的粗略修改替换
\chapter
为 使用\patchcmd
。添加
\usepackage[french]{babel}
,这会导致问题(french
添加到章节标题),因此取消勾选此答案