带图形的长章节标题:缩进且无连字符

带图形的长章节标题:缩进且无连字符

我已经获得了我想要的章节标题格式具有图形格式的章节

现在我遇到了章节标题过长的问题,因此我

格式错误的长标题章节示例

使用此代码

\documentclass{book} 

%PAGES
\usepackage[
    vcentering, 
    hcentering, 
    inner=16mm,
    outer=16mm,
    top=22.0mm, 
    bottom=15.0mm,
    headsep=9.3mm,
    headheight=5mm,
%   showframe
    ]
    {geometry} % Extended page layout customization

\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages
%\usepackage[cross,a4,center]{crop} %Package to print on A4 with crop signs. 
\usepackage{multicol}% handling of multicolumn in documents
\usepackage[toc]{multitoc}%enables table of contents with multiple columns
    \renewcommand*{\multicolumntoc}{2}% Set two columns for the table of contents
\usepackage{emptypage} % suppresses page numbers and headings on empty pages
\usepackage{xcolor}[2007/01/21] % Driver-independent color extensions

%SKETCHES AND PLOTS
\usepackage{tikz} % To create graphics programmatically. TikZ is build on top of PGF. 
    \usetikzlibrary{decorations.markings,arrows,backgrounds}
    \usetikzlibrary{patterns}
    \usetikzlibrary{shapes.misc, positioning}
    \usetikzlibrary{calc}

\usepackage{xcolor}[2007/01/21] % Driver-independent color extensions
    \definecolor{BlueGreen}{RGB}{7,116,159}
    \definecolor{LightBlue}{RGB}{185,229,251}
    \definecolor{LightGreen}{RGB}{203,231,211}  

%FONTS
\usepackage{fontspec}%LuaLaTex fonts
    \setmainfont[Ligatures=TeX,ItalicFont={Apollo MT Std Italic}]{Apollo MT}
\usepackage{titletoc,xpatch}%
\usepackage[explicit]{titlesec}% An in­ter­face to sec­tion­ing com­mands for se­lec­tion from var­i­ous ti­tle styles.

%Font families
\newfontfamily\Avenir{Avenir}
\newfontfamily\AvenirLight{Avenir Light}
\newfontfamily\AvenirHeavy{Avenir Heavy}


%Chapters in TOC 
\newcommand{\chaptertocfont}        {\fontsize{10}{12}\color{red}\AvenirHeavy}
\newcommand{\chaptertocpagefont}        {\fontsize{10}{12}\color{red}\AvenirHeavy}

%Chapters
\newcommand{\chapterfont}       {\fontsize{24}{27}\color{black}\AvenirLight}
\newcommand{\chapternrfont}     {\fontsize{24}{27}\color{BlueGreen}\AvenirHeavy}


\titlecontents{chapter}% section-type
    [1.5em]% <- changed
    {\vspace*{0.6cm}}
    {\chaptertocfont\contentslabel{1.5em}}% <- changed
    {\hspace*{-1.5em}}% <- changed
    {\hfill\chaptertocpagefont\contentspage}[]

%CHAPTER HEADINGS
\titlespacing{\chapter}{2cm}{-0.7cm}{1.7cm} % set spacing: left, before, after

\titleformat{\chapter}[hang]% command to be modified
    {\chapterfont} %format
    {\hspace*{-2.7cm}
        \tikz [anchor=base, baseline,remember picture, overlay]
        {% colorbox for the chapter number
        \node[
        line width = 1pt, 
        draw=BlueGreen, 
        fill =LightBlue, 
        anchor=base, 
        rectangle,  
        text width=2cm, 
        align=right, 
        rounded rectangle,
        rounded rectangle west arc=5pt, 
         minimum height=15mm,
        inner sep=11pt
        ] (A)
        {
        \chapternrfont\thechapter};
        \draw[line width = 1pt, red] let \p1=(A.south east), \p2=(current page.east) in  ([xshift=2.6ex]A.south east) -- +(\x2,0);
        }
    }% label
  {\dimexpr2em\relax}% sep
  {#1} % before-code
  [] % after-code

\begin{document} 

\tableofcontents

\chapter{Energy Conversion Systems}

\chapter[Thermodynamic Properties of \\ Multicomponent Fluids]{Thermodynamic Properties of \\ Multicomponent Fluids}

\end{document}

我尝试了所有我能找到的例子,但我无法让它看起来像 想要结果

我怎样才能使缩进、无连字符和红色标尺正确?

答案1

我没有您的字体,但也许以下内容有帮助:

\documentclass{book} 
\usepackage{lipsum}

\usepackage[
  vcentering, 
  hcentering, 
  inner=16mm,
  outer=16mm,
  top=22.0mm, 
  bottom=15.0mm,
  headsep=9.3mm,
  headheight=5mm,
%  showframe
]{geometry} % Extended page layout customization
\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages

\usepackage{fontspec}

\usepackage{multicol}% handling of multicolumn in documents

\usepackage{tikz} % loads also xcolor, graphicx, ...
\usetikzlibrary{shapes.misc}
\usetikzlibrary{calc}
\definecolor{BlueGreen}{RGB}{7,116,159}
\definecolor{LightBlue}{RGB}{185,229,251}
\definecolor{LightGreen}{RGB}{203,231,211}

\usepackage{emptypage}

\usepackage{tocbasic}
\addtotoclist[\jobname]{toc}
\renewcommand*\tableofcontents{\listoftoc[\contentsname]{toc}}
\BeforeStartingTOC[toc]{\begin{multicols}{2}}
\AfterStartingTOC[toc]{\end{multicols}}

\DeclareTOCStyleEntry[
  beforeskip=.6cm plus 1pt,
  entryformat=\chaptertocfont,
  pagenumberformat=\chaptertocpagefont,
  raggedentrytext=true
]{tocline}{chapter}
\newcommand*{\chaptertocfont}[1]{\normalsize\bfseries\textcolor{red}{#1}}
\newcommand*{\chaptertocpagefont}[1]{\chaptertocfont{#1}}

\usepackage[explicit]{titlesec}
\titlespacing{\chapter}{2cm}{-0.7cm}{1.7cm} % set spacing: left, before, after

\titleformat{\chapter}[hang]% command to be modified
  {\chapterfont} %format
  {\hspace*{-2.7cm}
    \tikz [baseline,remember picture, overlay]
    {% colorbox for the chapter number
    \node[
    line width = 1pt, 
    draw=BlueGreen, 
    fill =LightBlue, 
    anchor=base, 
    rectangle,  
    text width=2cm, 
    align=right, 
    rounded rectangle,
    rounded rectangle west arc=5pt, 
    minimum height=15mm,
    inner sep=11pt
    ] (A)
    {\chapternrfont\thechapter};
    }
  }% label
  {2em}% sep
  {%
    \tikz[baseline]{%
      \node[
        anchor=base,
        align=flush left,
        text height=\dp\strutbox,
        text width=\textwidth,
        inner xsep=0pt
      ](A){#1};
      \draw[
        overlay,
        line width = 1pt,
        red
        ]
        let \p1=(A.south west), \p2=(current page.east) in
        ([xshift=-.6ex]\p1) -- +(\x2,0);
    }%
  }% before-code
  []% after-code
\newcommand{\chapterfont}{\fontsize{24}{27}\selectfont\color{black}}
\newcommand{\chapternrfont}{\fontsize{24}{27}\selectfont\color{BlueGreen}\bfseries}

\begin{document} 
\tableofcontents
\chapter{Energy Conversion Systems}
\lipsum
\chapter{Thermodynamic Properties of Multicomponent Fluids}
\lipsum
\end{document}

结果:

在此处输入图片描述

如果未编号的目录标题下方不应该有行,则必须添加

\titleformat{name=\chapter,numberless}[hang]
  {\chapterfont} %format
  {}% label
  {0pt}% sep
  {#1}% before-code
  []% after-code

相关内容