漂亮的标题... \section{} 标题消失

漂亮的标题... \section{} 标题消失

通过结合接下来的两个问题答案精美的章节标题部分标题渐变 。我有这个效果。

问题是 的名称\section{}消失了。出了什么问题?

在此处输入图片描述

\documentclass[b5paper,svgnames,10pt]{book}
\usepackage[utf8x]{inputenc}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage[margin=1.5cm]{geometry}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
\usepackage[cm-default]{fontspec}
\setromanfont{FreeSerif}
\setsansfont{FreeSans}
\setmonofont{FreeMono}
\usepackage{xgreek}
\setmainfont{Arial}

%%%%%%%%%%%%%%%%%%%% fancy heading  \section %%%%%%%%%%%%%%%%%%%%%%

\titleformat{\section}[block]%              
    {\huge\bfseries%
     \tikz[overlay] \shade[left color=LightSkyBlue,right color=white,] (0,-1ex) rectangle (\textwidth,1em);}%    
    {\thesection}%                   
    {1em}%
    {}

%%%%%%%%%%%%%%%%%% fancy heading  \chapter %%%%%%%%%%%%%%%%%%%%%%%%

\newcommand*\chapterlabel{}
\titleformat{\chapter}
{\gdef\chapterlabel{}
  \normalfont\sffamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
    {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=LightSkyBlue] (0,0) rectangle
        (\paperwidth,3cm);
        \node[anchor=east,xshift=.9\paperwidth,rectangle,
        rounded corners=20pt,inner sep=11pt,
        fill=MidnightBlue]
        {\color{white}\chapterlabel#1};
      \end{tikzpicture}
    };
  \end{tikzpicture}
}
\titlespacing*{\chapter}{0pt}{50pt}{0pt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\part{Ενέργεια}

\chapter{Κινητική}

\section{Κινήσεις}
\lipsum[1]

\section{Δυναμική}
\lipsum[1]

\end{document}

答案1

explicit使用 的包选项时titlesec,必须在格式定义中明确给出标题,例如:

\titleformat{\section}[block]%              
    {\huge\bfseries%
     \tikz[overlay] \shade[left color=LightSkyBlue,right color=white,] (0,-1ex) rectangle (\textwidth,1em);}%    
    {\thesection}%                   
    {1em}%
    {#1}

正确的位置通常是的最后一个强制参数\titleformat,即before-code。该参数#1扩展到标题。

相关内容