
我喜歡這裡的盒子章節樣式:http://hstuart.dk/2007/05/21/styling-the-chapter/
這是基於這種風格的 MWE:
\documentclass{memoir}
\usepackage{tikz, blindtext}
\makechapterstyle{box}{
\renewcommand*{\printchaptername}{}
\renewcommand*{\chapnumfont}{\normalfont\sffamily\huge\bfseries}
\renewcommand*{\printchapternum}{
\flushright
\begin{tikzpicture}
\draw[fill,color=black] (0,0) rectangle (2cm,2cm);
\draw[color=white] (1cm,1cm) node { \chapnumfont\thechapter };
\end{tikzpicture}
}
\renewcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries}
\renewcommand*{\printchaptertitle}[1]{\flushright\chaptitlefont##1}
}
\chapterstyle{box}
\begin{document}
\chapter{Fancy chapter with TikZ}
\blindtext
\end{document}
現在我想消除一些由 1 和 2 表示的空白(因此在框的上方和下方,但大部分在框的上方)。當然應該有一點空白,但我不希望章節標題佔用太多空間,所以它應該相當小。關於如何實現這一目標有什麼想法嗎?
額外問題:是否可以在允許我使用該類別的同時完成所有這些report
操作(我不知道該類別memoir
以後可能會給我帶來什麼缺點)?
提前致謝。
答案1
你在這。
\documentclass{report}
\usepackage{tikz, blindtext,showframe} %% blindtext,showframe just for demo
\usepackage{titlesec}
\newcommand*{\chapnumfont}{\normalfont\sffamily\huge\bfseries}
\newcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries}
\newcommand{\mybox}{%
\begin{tikzpicture}
\draw[fill,color=black] (0,0) rectangle (2cm,2cm);
\draw[color=white,font=\chapnumfont] (1cm,1cm) node {\thechapter};
\end{tikzpicture}%
}
\titleformat{\chapter}[display]
{}{\filleft\mybox}{20pt}{\filleft\chaptitlefont}
\titlespacing*{\chapter} {0pt}{0pt}{0pt}
\begin{document}
\chapter{Fancy chapter with TikZ}
\blindtext
\end{document}
調整其中的值,預設\titlespacing*{\chapter} {0pt}{0pt}{0pt}
情況下\titlespacing*{\chapter} {0pt}{50pt}{40pt}
,我已將它們全部設為零。
in 20pt
in是章節號和標題之間...\mybox}{20pt}...
的\titleformat
垂直間距。如果你願意的話可以調整。
答案2
您要設定的具體參數memoir
:
\documentclass{memoir}
\usepackage{tikz, blindtext,showframe}
\makechapterstyle{box}{%
\setlength{\beforechapskip}{0pt}% was 50pt
\setlength{\midchapskip}{20pt}%
\setlength{\afterchapskip}{20pt}% was 40pt
\renewcommand*{\printchaptername}{}%
\renewcommand*{\chapnumfont}{\normalfont\sffamily\huge\bfseries}%
\renewcommand*{\printchapternum}{%
\flushright
\begin{tikzpicture}
\draw[fill,color=black] (0,0) rectangle (2cm,2cm);
\draw[color=white] (1cm,1cm) node { \chapnumfont\thechapter };
\end{tikzpicture}%
}%
\renewcommand*{\chaptitlefont}{\normalfont\sffamily\Huge\bfseries}%
\renewcommand*{\printchaptertitle}[1]{\flushright\chaptitlefont##1}%
}
\chapterstyle{box}
\begin{document}
\chapter{Fancy chapter with TikZ}
\blindtext
\end{document}
我曾經showframe
使各個頁面部分的邊界框變得明顯。