自定义章节标题

自定义章节标题

如何用 LaTex 制作这个?

在此处输入图片描述

我已经用这个制作章节标题了:

\def\@makechapterhead#1{%
\vspace*{10\p@}%
{\parindent \z@
{\reset@font
\usefont{OT1}{phv}{m}{n}
\LARGE Chapitre \thechapter\par\nobreak}%
\par\nobreak
\vspace*{30\p@}
\interlinepenalty\@M
\usefont{OT1}{ptm}{b}{n}
{\raggedright \Huge #1}%
\par\nobreak
\vskip 20\p@
\hrule height 1pt
\par\nobreak
\vskip 45\p@
}}

\def\@makeschapterhead#1{%
\vspace*{10\p@}%
{\parindent \z@
{\raggedleft \reset@font
\scshape \vphantom{\@chapapp{} \thechapter}
\par\nobreak}%
\par\nobreak
\vspace*{30\p@}
\interlinepenalty\@M
\usefont{OT1}{ptm}{b}{n}
{\raggedright \Huge #1}%
\par\nobreak
\par\nobreak
\vskip 45\p@
}}

请问有什么好主意吗?

答案1

这是一种 »标题安全« 您可能需要合并您的字体设置。

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[explicit]{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}

\titleformat{\chapter}[hang]
{\filcenter}
{\parbox{\widthof{\LARGE\sffamily\MakeUppercase{\chaptername}\enspace}}{%
  \filcenter\Large\sffamily\MakeUppercase{\chaptername}\enspace\\%
  \fontsize{48pt}{48pt}\selectfont\thechapter}\vrule width 2pt\quad%
}
{0pt}
{\Huge\bfseries\sffamily\parbox{\textwidth-\widthof{\LARGE\sffamily\MakeUppercase{\chaptername}\enspace}}{\filright #1}}

\begin{document}
  \chapter{A Very Long Title with Line Break}
    \lipsum[1]
\end{document}

在此处输入图片描述


附录

与评论相对应,这是一个改编的(并且略有增强)版本,其中完整标题采用 Helvetica 字体。

\documentclass[11pt]{report}
\usepackage[T1]{fontenc}
\usepackage[explicit]{titlesec}
\usepackage{calc}
\usepackage{lmodern}
\usepackage{lipsum}

\titleformat{\chapter}[hang]
{\filcenter}
{\parbox{\widthof{\LARGE\sffamily\MakeUppercase{\chaptername}}}{%
   \filcenter\Large\usefont{T1}{phv}{m}{n}\MakeUppercase{\chaptername}\\%
   \fontsize{48pt}{48pt}\selectfont\thechapter%
 }\enspace%
}
{0pt}
{\Huge\usefont{T1}{phv}{b}{n}\vrule width 1pt \enspace%
 \parbox{\textwidth-\widthof{\LARGE\sffamily\MakeUppercase{\chaptername}\enspace}}{\filright #1}%
}

\begin{document}
  \setcounter{chapter}{9}
  \chapter{Chapter Title}
    \lipsum[1]
\end{document}

如果您需要为图片中所示的章节添加某种副标题,则必须使用可选参数。

  \chapter[Hello, ATL Server]{Hello, ATL Server\\[6pt] \large A Modern C++ Web Platform}

有兴趣的读者可以判断这是否有用。


在此处输入图片描述


如果你想知道如果章节标题(不必要地)太长并且超过两行会发生什么,你可以看看这个。

在此处输入图片描述

但实际上应该避免这种情况。如您所见,垂直规则会适应实际标题的内容,而章节名称和章节编号则保留在其位置。

答案2

另一个解决方案也使用 titlesec,但使用表格环境:

        \documentclass[12pt,a4paper]{book}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}
        \usepackage{microtype} 

        \usepackage[svgnames, x11names]{xcolor} 
        \newcommand*\ftsize[1]{\fontsize{#1pt}{\numexpr 1.2*#1\relax pt}\selectfont}
        \newcommand*\chapsubtitle[1]{{\LARGE #1}}
        \newcommand\maketabular[1]{\begin{tabular}[b]{l}
          #1
        \end{tabular}}
        \usepackage{colortbl} 
        \usepackage{titlesec}
        \titleformat{\chapter}[block]{\usefont{T1}{phv}{m}{n}}{%
        \begin{tabular}[b]{c !{\color{lightgray}\vline width1.2pt}}{\large\color{lightgray} \textls*{CHAPTER}}\\[4ex] \fontsize{72}{72}\selectfont\thechapter\end{tabular}}{1em}{\bfseries\fontsize{36}{48}\selectfont\maketabular}%[]


        \begin{document}
        \setcounter{chapter}{12}
        \chapter{Hello,  ATL Server\\ \chapsubtitle{A Modern C++ Web Platform}}%

        \end{document} 

在此处输入图片描述

如果标题有几行,只需进行简单的修改即可:不要只写一行\\[4ex],而是写与标题行数相同的行。以下是使用\\[4ex]\\[4ex]\\[4ex]和 的结果

\chapter{Hello,  ATL Server\\ A Longer Title \\ %
A Still Longer Title \\\chapsubtitle{A Modern C++ Web Platform}}

在此处输入图片描述

还有一个例子,关于目录。需要使用 \chapter 的可选参数:1) 因为 \subtitle 命令将“按原样”合并(即使用 \large 说明符);2) 如果标题有多行,titlesec 选项:newlinetospace似乎不起作用 - 或者我错过了什么。该选项应该会自动将标题中的任何 \ 替换为空格,以便在页眉和目录中使用。

        \documentclass[11pt,a4paper]{report}
        \usepackage[utf8]{inputenc}
        \usepackage[T1]{fontenc}
        \usepackage{MinionPro} 
        \usepackage[nomarginpar]{geometry} 

        \usepackage{microtype} 

        \usepackage[svgnames, x11names]{xcolor} 
        \newcommand*\ftsize[1]{\fontsize{#1pt}{\numexpr 1.2*#1\relax pt}\selectfont}
        \newcommand*\chapsubtitle[1]{{\LARGE #1}}
        \newcommand\maketabular[1]{\begin{tabular}[b]{l}
          #1
        \end{tabular}}
        \usepackage{colortbl} 
        \usepackage[explicit,newlinetospace]{titlesec}% 

        \titleformat{\chapter}[block]{\usefont{T1}{phv}{m}{n}}{%
        \begin{tabular}[b]{c}{ \large\color{lightgray} \textls*{CHAPTER}}\\[4ex] \fontsize{48}{48}\selectfont\thechapter\end{tabular}}{1em}{\bfseries\fontsize{24}{30}\selectfont
        \begin{tabular}[b]{ !{\color{lightgray}\vline width1.2pt\ }l}
          #1
        \end{tabular}}
        \titlespacing{\chapter}{0pt}{2\baselineskip}{6\baselineskip}
        \begin{document}%

        \chapter[The History of the Seven Families of the Lake Pipple-Popple]
        {The History of the\\Seven Families of the\\Lake Pipple-Popple\\
        \chapsubtitle{A nonsense story}}%

       In former days -- that is to say, once upon a time, there lived in the Land of Gramblamble, Seven Families. They lived by the side of the great Lake Pipple-popple (one of the Seven Families, indeed, lived in the Lake), and on the outskirts of the City of Tosh, which, excepting when it was quite dark, they could see plainly. The names of all these places you have probably heard of, and you have only not to look in your Geography books to find out all about them.

       Now the Seven Families who lived on the borders of the great Lake Pipple-popple, were as follows in the next Chapter.

        \tableofcontents

        \end{document} 

在此处输入图片描述

相关内容