在下面的 MWE 中,我安排了章节标题的位置(在这种情况下,我只需要数字),使其位于与页边接触的角落。如何完全删除在其周围创建的间距,以便文本从没有章节条目的位置开始?
\documentclass[12pt, oneside]{book}
\usepackage[showframe, paperwidth=30pc, paperheight=30pc, margin=5pc]{geometry}
\usepackage{tikz}
\usepackage{titlesec}
\titleformat{\chapter}
[block]% shape
{\filcenter\bfseries\large}% format applied to label+text
{}% label
{0pt}% horizontal separation between label and title body
{\maketitleframe{\thechapter}}% before the title body
\titlespacing{\chapter}{0pt}{0pt}{0pt}
\newcommand{\maketitleframe}[2]{%
\begin{tikzpicture}[overlay,remember picture]
\node[draw, rectangle, minimum size=5pc, yshift=-2.5pc, xshift=2.5pc] at (current page.north west) {#1};
\end{tikzpicture}% before the title body
}
\begin{document}
\chapter{}
test
\end{document}
答案1
同时改变\titlespacing
的\chapter
:
\documentclass[12pt, oneside]{book}
\usepackage[showframe, paperwidth=30pc, paperheight=30pc, margin=5pc]{geometry}
\usepackage{tikz}
\usepackage{titlesec}
\titleformat{\chapter}
[block]% shape
{}% format applied to label+text
{}% label
{0pt}% horizontal separation between label and title body
{\maketitleframe{\thechapter}}% before the title body
\titlespacing{\chapter}{0pt}{0pt}{-2\baselineskip}
\newcommand{\maketitleframe}[2]{%
\begin{tikzpicture}[overlay,remember picture]
\node[draw, rectangle, minimum size=5pc, yshift=-2.5pc, xshift=2.5pc] at (current page.north west) {#1};
\end{tikzpicture}% before the title body
}
\begin{document}
\chapter{}
test
\end{document}
但是,如果您只想要数字,并且不需要运行头和目录条目,那么您只需放置tikzpicture
而不使用\chapter
:
\documentclass[12pt, oneside]{book}
\usepackage[showframe, paperwidth=30pc, paperheight=30pc, margin=5pc]{geometry}
\usepackage{tikz}
\newcommand*{\chapternum}{%
\clearpage
\refstepcounter{chapter}%
\begin{tikzpicture}[overlay,remember picture]
\node[draw, rectangle, minimum size=5pc, yshift=-2.5pc, xshift=2.5pc] at (current page.north west) {\thechapter};
\end{tikzpicture}%
\ignorespaces
}
\begin{document}
\chapternum
test
\end{document}
或使用目录条目和运行头:
\documentclass[12pt, oneside]{book}
\usepackage[showframe, paperwidth=30pc, paperheight=30pc, margin=5pc]{geometry}
\usepackage{tikz}
\newcommand{\chapternum}[1]{%
\clearpage
\refstepcounter{chapter}%
\chaptermark{#1}%
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
\begin{tikzpicture}[overlay,remember picture]
\node[draw, rectangle, minimum size=5pc, yshift=-2.5pc, xshift=2.5pc] at (current page.north west) {\thechapter};
\end{tikzpicture}%
\ignorespaces
}
\begin{document}
\tableofcontents
\chapternum{}
test
\chapternum{ToC Entry and Head}
test
\clearpage
test
\clearpage
test
\end{document}