使用 LaTeX 格式化標題

使用 LaTeX 格式化標題

我遇到了一個文件在網路上發現這個文件中使用的標題非常吸引我。如何製作一個標頭格式:<chpater-name> | <page-number>和類似的顏色/字體?

答案1

這裡有一個建議KOMA-Script 類使用包scrlayer-scrpage

\documentclass[headings=optiontoheadandtoc]{scrbook}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage[letterspace=200]{microtype}% https://www.ctan.org/pkg/microtype

\usepackage[automark,markcase=upper]{scrlayer-scrpage}% 
\clearpairofpagestyles
\lehead*{\pagemark\mypagenumberbar\leftmark}
\rohead*{\leftmark\mypagenumberbar\pagemark}

\renewcommand{\chaptermarkformat}{}% no chapter number in page header
\newcommand\mypagenumberbar{{\usekomafont{pagenumber}{\enskip\rule[-\dp\strutbox]{1pt}{\baselineskip}\enskip}}}
\setkomafont{pageheadfoot}{\color{gray}\sffamily\textls}% font settings for page header and footer
\setkomafont{pagenumber}{\normalcolor}% normal color for page numbers

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter[head=General]{General Suggestions}
\lipsum[1-10]
\chapter[head=Delivery]{Delivery of the Thesis}
\lipsum[1-10]
\chapter{Cover Sheet}
\lipsum[1-10]
\end{document}

在此輸入影像描述

附加說明:

類別選項headings=optiontoheadandtoc啟動切片命令的可選參數的擴展解釋。例如。\chapter[head=General]{General Suggestions}將「一般」放在運行標題中,而將「一般建議」放在目錄中。

\lehead和的加星號版本\rohead對頁面樣式scrheadingsplain( 的別名plain.scrheadings)使用強制參數。因此,您也會在章節頁面上看到標題。


也可以使用包包scrlayer-scrpage標準級

\documentclass{book}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage[letterspace=200]{microtype}% https://www.ctan.org/pkg/microtype

\usepackage[markcase=upper]{scrlayer-scrpage}% 
\clearpairofpagestyles
\lehead*{\pagemark\mypagenumberbar\leftmark}
\rohead*{\leftmark\mypagenumberbar\pagemark}

\renewcommand{\chaptermark}[1]{\markboth{\MakeMarkcase{#1}}{}}% no chapter number in page header
\newcommand\mypagenumberbar{{\usekomafont{pagenumber}{\enskip\rule[-\dp\strutbox]{1pt}{\baselineskip}\enskip}}}
\setkomafont{pageheadfoot}{\color{gray}\sffamily\textls}% font settings for page header and footer
\setkomafont{pagenumber}{\normalcolor}% normal color for page numbers

\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{General Suggestions}\chaptermark{General}
\lipsum[1-10]
\chapter{Delivery of the Thesis}\chaptermark{Delivery}
\lipsum[1-10]
\chapter{Cover Sheet}
\lipsum[1-10]
\end{document}

在此輸入影像描述

答案2

這是來自您提供的連結文件:

連結圖片

這就是我提供的程式碼產生的結果:

在此輸入影像描述

代碼:

\documentclass{book}

\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage[letterspace=200]{microtype} % https://tex.stackexchange.com/a/62351/245306

% https://tex.stackexchange.com/a/400110/245306
\newcommand\mybar{\kern1pt\rule[-\dp\strutbox]{.8pt}{\baselineskip}\kern1pt}

\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} % Changed this to include chapter name only

\fancyhead[R]{{\color{gray} \sffamily \textls{\MakeUppercase\leftmark}} \textbf{\mybar\ \thepage}}

\renewcommand{\headrulewidth}{0pt}      % Removes head rule

\begin{document}
\mainmatter
\chapter{Introduction}
\lipsum[1-10]
\chapter{Methodology}
\lipsum[1-10]
\end{document}

程式碼相當醜陋,但按照您的要求執行,此處採用了引用的 TEX.SE 答案microtype和自訂命令\mybar,如果您想進一步自訂它們,答案中將更詳細地解釋它們。希望這對您有所幫助,如果您需要進一步的信息,請發表評論,我會盡力解釋更多。

編輯:刪除然後編輯程式碼和圖像,因為我\chaptername錯誤地使用了程式碼和圖像,而不是\leftmark在自訂之後。

相關內容