我想删除书籍类中的标题“第 1 章”、“第 2 章”等,只保留章节名称作为标题,并在目录中更新它。但是当我给出 chapter* 时,它不会在目录中显示章节名称。这是我的代码:
\documentclass[oneside]{book}
%\title{Web Blog} %use titlesec
%\subtitle{Software Requirement Specification}
%\author{Subham Soni.S}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
%\maketitle
\begin{titlepage}
\begin{tikzpicture}[remember picture,overlay]
\draw[magenta,line width=5pt] ($(current page.north west) +(1in,-0.5in)$) -- ($(current page.south west) +(1in,0.5in)$);
\end{tikzpicture}
\begin{center}
\vspace*{1in}
\Huge WEB BLOG
\vspace{1in}
\LARGE Software Requirement Specification
\end{center}
\end{titlepage}
\tableofcontents
\include{./preface/preface}
\include{./purpose/purpose}
\include{./scope/scope}
\end{document}
前言tex文档:
\chapter{Preface}
\paragraph*{Blog}is an abbreviated version of \textbf{weblog} which is a term used to describe web sites that maintain an ongoing chronicle of information. A blog features diary-type commentary and links to articles on other Web sites, usually presented as a list of entries in reverse chronological order. Blogs range from the personal to the political, and can focus on one narrow subject or a whole range of subjects. \par
\textit{This document is intended for any individual user, developer, tester, project manager or documentation writer that needs to understand the basic system architecture and specifications of a web blog.}
目的 tex 文件:
\chapter*{Purpose}
%\addcontentsline{toc}{Chapter}{Purpose}
\paragraph*{}The purpose of the project is to provide users to create and manage their own blogs in various domains.There are three types of users, the \textit{Administrator}, the \textit{Blog Owner} and the \textit{Blog Viewer}.The Administrator has full control over the website, can delete the users or blogs if required. The Blog owner can create, edit, and delete blogs. The Blog viewer can view, comment the blogs and share them.
范围 tex 文档:
\chapter{Scope and Limitations}
\paragraph*{}
The scope and limitations of this system are:
\begin{itemize}
\item The web blog is designed for a limited number of domains so that it is feasible.
\item The web blog restricts the number of posts if the owners present average blog ratings are not above 3.
\item The members can view the blog and share them on social media networks.
\end{itemize}
在 TeXMaker 中,如何将 Documentataion.tex(第一组代码)设为主文件?
答案1
含titlesec
包装:
\documentclass[oneside]{book}
\usepackage{titlesec}
\usepackage{lipsum} % only for the example
\titleformat{\chapter}
{\normalfont\Huge\bfseries}
{}
{0pt}
{}
\titlespacing*{\chapter}{0pt}{*11.5}{*8}
\renewcommand{\chaptermark}[1]{\markright{\MakeUppercase{#1}}}
\usepackage[colorlinks]{hyperref}
\begin{document}
\tableofcontents
\chapter{First}
\lipsum[1]
\section{test}
\lipsum[1-5]
\chapter{Second}
\end{document}
答案2
要将其设置Documentation.tex
为 TeXMaker 中的主文件,您必须转到“选项”菜单并单击“将当前文档定义为‘主文档’”。
回答您的主要问题,如果您希望所有章节都在目录中编号但不在文档中编号,您可以创建一个新的章节命令,\chapterstar
如下所示(也可以使用hyperref
):
\newcommand{\chapterstar}[1]{%
\refstepcounter{chapter}%
\chapter*{#1}%
\markright{\MakeUppercase{#1}}%
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
}
\refstepcounter{chapter}
chapter
每次发出该命令时都会增加计数器,同时\markright{\MakeUppercase{#1}}
用于在标题中获取正确的内容。
最后\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}
在目录中添加正确的内容。
这是一个使用示例:
\documentclass[oneside]{book}
\usepackage[colorlinks]{hyperref}
\usepackage{lipsum} % only for the example
\newcommand{\chapterstar}[1]{%
\refstepcounter{chapter}%
\chapter*{#1}%
\markright{\MakeUppercase{#1}}%
\addcontentsline{toc}{chapter}{\protect\numberline{\thechapter}#1}%
}
\begin{document}
\tableofcontents
\chapterstar{First}
\lipsum[1]
\section{test}
\lipsum[1-5]
\chapterstar{Second}
\end{document}
输出:
编辑
有了上述解决方案,您可以在需要时使用,并且如果需要的话还可以\chapterstar
继续使用。\chapter
\chapter*
以下解决方案重新定义了上述解决方案中的\chapter
行为方式的含义,因此您可以使用而不是,但请注意原始版本不再可用。\chapterstar
\chapter
\chapterstar
\chapter
重新定义\chapter
包括(需要etoolbox
包):
\makeatletter
\let\@makechapterhead\@makeschapterhead
\patchcmd{\@chapter}{\chaptermark{#1}}{\markright{\MakeUppercase{#1}}}{}{}
\makeatother
hyperref
在这种情况下请记住在其后加载。
以下 MWE 产生与上述相同的结果:
\documentclass[oneside]{book}
\usepackage{etoolbox}
\usepackage{lipsum} % only for the example
\makeatletter
\let\@makechapterhead\@makeschapterhead
\patchcmd{\@chapter}{\chaptermark{#1}}{\markright{\MakeUppercase{#1}}}{}{}
\makeatother
\usepackage[colorlinks]{hyperref}
\begin{document}
\tableofcontents
\chapter{First}
\lipsum[1]
\section{test}
\lipsum[1-5]
\chapter{Second}
\end{document}