章节标题中的 Tikz 图片与章节正文之间的间距

章节标题中的 Tikz 图片与章节正文之间的间距

以下是最小工作示例

 \documentclass[a4paper,11pt]{book} 
\usepackage{lipsum}
\usepackage{color}                                                     
\usepackage{tikz}                                                      
\usepackage[explicit]{titlesec}                                        
\newcommand*\chapterlabel{}                                            
%\renewcommand{\thechapter}{\Roman{chapter}}                           
\titleformat{\chapter}[display]  % type (section,chapter,etc...) to vary,  shape (eg display-type)
        {\normalfont\bfseries\Huge} % format of the chapter            
        {\gdef\chapterlabel{\thechapter\ }}     % the label            
        {0pt} % separation between label and chapter-title             
          {\begin{tikzpicture}[remember picture,overlay]               
    \node[yshift=-8cm] at (current page.north west)                    
      {\begin{tikzpicture}[remember picture, overlay]                  
        \draw[fill=black] (0,0) rectangle(35.5mm,15mm);                
        \node[anchor=north east,yshift=-7.2cm,xshift=34mm,minimum
height=30mm,inner sep=0mm] at (current page.north west)
        {\parbox[top][30mm][t]{15mm}{\raggedleft
$\phantom{\textrm{l}}$\color{white}\chapterlabel}};  %the black l is just to get better base-line alingement
        \node[anchor=north west,yshift=-7.2cm,xshift=37mm,text
width=\textwidth,minimum height=30mm,inner sep=0mm] at (current
page.north west)
              {\parbox[top][30mm][t]{\textwidth}{\color{black}#1}};    
       \end{tikzpicture}                                               
      };                                                               
   \end{tikzpicture}                                                   
   \gdef\chapterlabel{}                                                
  } % code before the title body 
\begin{document}
\frontmatter                                                           
{\huge TITLE} \\[24pt]
\setcounter{page}{0}
\mainmatter
\chapter{A very very very very very very very very very very very very
very very very very very very very very very very very very very very
very very long title}
\lipsum[7]

\end{document}

产生以下章节页面: 在此处输入图片描述

问题在于正文和章节标题之间的间距不正确。间距似乎是根据黑色矩形的底部计算的,而不是根据章节标题的底部计算的。

是否可以调整间距,使得文本正文和章节标题之间的距离始终相同(与章节标题所需的行数无关)?

答案1

由于该overlay选项,章节标题的高度不予考虑。但没有必要使用tikz

以下是使用黑色的建议\colorbox

\documentclass[a4paper,11pt]{book} 
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[hang]
        {\normalfont\bfseries\Huge}
        {\makebox[.5ex][r]{\colorbox{black}{%
            \hspace*{5cm}\rule[-1.5mm]{0pt}{13mm}\color{white}\thechapter\,%
          }}\,}
        {0pt}{#1}
\begin{document}
\frontmatter
{\huge TITLE\par}
\mainmatter
\chapter[short title]{A very very very very very very very very very very very very
very very very very very very very very very very very very very very
very very long title}
\lipsum[7]
\setcounter{chapter}{99}
\chapter[short title]{A very very very very very very very very very very very very
very very very very very very very very very very very very very very
very very long title}
\lipsum[7]
\end{document}

在此处输入图片描述

相关内容