
在下面的 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}