我正在尝试制作我自己的章节样式。几乎成功了...但是,出现了两个问题。首先,样式也出现在不是我想要的内容中。其次,蓝色条的位置不对。我该如何解决这两个问题?谢谢!以下是示例代码:
\documentclass{book}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{xcolor}
\titleformat{\chapter}[display]{%
\begin{tikzpicture}
\path [fill=blue!20] (0,1) rectangle (\textwidth,2);
\end{tikzpicture}
\flushleft%
}{\fontsize{96pt}{96pt}\bfseries\thechapter}{0pt}{\Huge\color{blue}}
\begin{document}
\tableofcontents
\chapter{example1}
\section{hahaha}
\chapter{example2}
\section{sososos}
\end{document}
答案1
像这样?
\documentclass{book}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{xcolor}
\titleformat{\chapter}[display]{%
\flushleft%
}{
\begin{tikzpicture}
\node[anchor=south west] (chap) at (0.1,1.3){\fontsize{96pt}{96pt}\bfseries\thechapter};
\path [fill=blue!20] (0,1) rectangle (\textwidth,0);
\path(0,-0.2);
\end{tikzpicture}
}{-3mm}{\Huge\color{blue}}
\begin{document}
\tableofcontents
\chapter{example1}
\section{hahaha}
\chapter{example2}
\section{sososos}
\end{document}