有人能提出一种方法来以给定的文档为起点实现以下章节样式吗?(数字“1”是章节编号)
\documentclass{book}
\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}
\titleformat{\chapter}[display]
{}{\rule{.7\textwidth}{2pt}}{0pt}
{\hspace*{.3\textwidth}\huge\bfseries}[\addvspace{-1pt}]
\begin{document}
\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}
\end{document}
答案1
explicit
使用带有 的选项titlesec
。此代码会给出与您的图片非常接近的内容。
\documentclass{book}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}
\newcommand\myfancychapter{\tikz[baseline=(CHAP.base),very thick]{
\draw[use as bounding box,draw=white,fill=white] (0,0) rectangle (2cm,2cm);
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP) at
(1cm,\baselineskip+1ex) {\Huge{\textbf{\textsf{\thechapter}}}};
\draw[draw=gray!30!white,fill=gray!30!white] (2cm,0cm) rectangle (\textwidth,2cm);
\draw[black, ultra thick](0,1.2cm) -- (\textwidth,1.2cm);
\draw[black, ultra thick](2cm,0cm) -- (2cm,2cm);
}}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}
\titleformat{\chapter}
{\normalfont}{\myfancychapter}{1em}{\LARGE{\textbf{#1}}}
\begin{document}
\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}
\end{document}
我只是将数字移到了线下,因为我觉得这样看起来更好。但tikz
您可以完全控制。
编辑:这是将部分编号移到线上的“最小损坏”方法。我还必须将框变大。
\documentclass{book}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}
\newcommand\myfancychapter{\tikz[baseline=(CHAP.base),very thick]{
\draw[use as bounding box,draw=white,fill=white] (0,0) rectangle (2cm,2.5cm);
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP) at
(1cm,\baselineskip+1ex) {\phantom{\Huge{\textbf{\textsf{\thechapter}}}}};
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP2) at
(1cm,1.8cm) {\Huge{\textbf{\textsf{\thechapter}}}};
\draw[draw=gray!30!white,fill=gray!30!white] (2cm,0cm) rectangle (\textwidth,2.5cm);
\draw[black, ultra thick](0,1.2cm) -- (\textwidth,1.2cm);
\draw[black, ultra thick](2cm,0cm) -- (2cm,2.5cm);
}}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}
\titleformat{\chapter}
{\normalfont}{\myfancychapter}{1em}{\LARGE{\textbf{#1}}}
\begin{document}
\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}
\end{document}
第二次编辑:内置@egreg 的建议。(谢谢!)
答案2
我认为你不需要用大锤来做这件事:tabularx
,booktabs
并且colortbl
可以做到:
\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in, showframe]{geometry}
\usepackage{tabularx, booktabs}
\usepackage[table, svgnames]{xcolor}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}
\titleformat{\chapter}[block]
{\huge\bfseries}{}{0pt}
{\setlength{\extrarowheight}{3pt}\begin{tabularx}{\textwidth}{ >{\filcenter}p{1cm}!{\vrule width 2pt} >{\columncolor{Gainsboro!50!Lavender}[\tabcolsep][0pt]\filcenter}X@{}}\thechapter & \\ \specialrule{2pt}{0pt}{0pt}\end{tabularx}}[\addvspace{-1pt}]
\begin{document}
\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}
\end{document}