如何使用“book”文档类从标题中删除“Chapter”一词

如何使用“book”文档类从标题中删除“Chapter”一词

我正在为自己开发的应用程序编写用户手册,使用的是书籍文档类。我可以从章节开头和目录中删除“章节”一词,这样它只显示编号和章节名称。但我不知道如何从页眉中删除它。MWE(可能不是那么小......)如下:

% !TeX encoding = UTF-8
\documentclass[letterpaper,12pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[spanish]{layout}
\usepackage{graphics,graphicx}
\usepackage[bottom=2.5cm,top=3cm,left=1.8cm,right=1.8cm,footnotesep=0.5cm]{geometry} % ,showframe
\usepackage[flushmargin]{footmisc}

\makeatletter
\def\@makechapterhead#1{%
    \vspace*{50\p@}%
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
        %\huge\bfseries \@chapapp\space \thechapter
        \Huge\bfseries \thechapter.\space%
        %\par\nobreak
        %\vskip 20\p@
        \fi
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
    }
}
\def\@makeschapterhead#1{%
    \vspace*{50\p@}%
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
        %\huge\bfseries \@chapapp\space \thechapter
        \Huge\bfseries \thechapter.\space%
        %\par\nobreak
        %\vskip 20\p@
        \fi
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
    }
}
\makeatother
\addtolength{\footnotesep}{2.5mm}
\renewcommand{\thefootnote}{\textbf{\arabic{footnote}}}

\begin{document}

\begin{titlepage}
    \centering
    %\includegraphics[width=6cm]{pics/logo.png}
    \par\vspace{1cm}
    {\scshape\LARGE Company's shortname\par}
    \par\vspace{1cm}
    {\scshape\LARGE Manual de Usuario \par}
    \par\vspace{1cm}
    {\scshape\Large Company's name \par}
    \vfill
    {\scshape My name ;) \par}
    \today \par
\end{titlepage}

\frontmatter
\tableofcontents

%\include{./TeX_files/intro}
\mainmatter
%\include{./TeX_files/primeros_pasos}
%\include{./TeX_files/cap_actas}
%\include{./TeX_files/cap_fotos}
\chapter{This is a chapter}
Some filler text here... \footnote{This is the footnote.}

\backmatter
% bibliography, glossary and index would go here.

\end{document}

其结果如下图所示:

目录 章节开始 我面临的问题

提前致谢! ;)

答案1

您还需要修改\chaptermark

\documentclass[letterpaper,12pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}

\usepackage[
  bottom=2.5cm,
  top=3cm,
  left=1.8cm,
  right=1.8cm,
  footnotesep=0.5cm,
%  showframe,
]{geometry}

\usepackage[flushmargin]{footmisc}
\usepackage{graphicx}

\usepackage{lipsum} % just for the test

\makeatletter
\def\@makechapterhead#1{%
    \vspace*{50\p@}%
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
        %\huge\bfseries \@chapapp\space \thechapter
        \Huge\bfseries \thechapter.\space%
        %\par\nobreak
        %\vskip 20\p@
        \fi
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
    }
}
\def\@makeschapterhead#1{%
    \vspace*{50\p@}%
    {\parindent \z@ \raggedright \normalfont
        \ifnum \c@secnumdepth >\m@ne
        \if@mainmatter
        %\huge\bfseries \@chapapp\space \thechapter
        \Huge\bfseries \thechapter.\space%
        %\par\nobreak
        %\vskip 20\p@
        \fi
        \fi
        \interlinepenalty\@M
        \Huge \bfseries #1\par\nobreak
        \vskip 40\p@
    }
}
\renewcommand{\chaptermark}[1]{%
  \markright{%
    \MakeUppercase{%
      \ifnum\c@secnumdepth>\m@ne
        \if@mainmatter
          %\@chapapp \ %
          \thechapter. \ %
        \fi
      \fi
      #1%
    }%
  }%
}
\makeatother
\addtolength{\footnotesep}{2.5mm}
\renewcommand{\thefootnote}{\textbf{\arabic{footnote}}}

\begin{document}

\begin{titlepage}
    \centering
    %\includegraphics[width=6cm]{pics/logo.png}
    \par\vspace{1cm}
    {\scshape\LARGE Company's shortname\par}
    \par\vspace{1cm}
    {\scshape\LARGE Manual de Usuario \par}
    \par\vspace{1cm}
    {\scshape\Large Company's name \par}
    \vfill
    {\scshape My name ;) \par}
    \today \par
\end{titlepage}

\frontmatter
\tableofcontents

\mainmatter

\chapter{This is a chapter}
Some filler text here... \footnote{This is the footnote.}

\lipsum[1-15]

\backmatter
% bibliography, glossary and index would go here.

\end{document}

\@chapapp我保留了通过默认命令插入的部分。

在此处输入图片描述

答案2

您可以在序言中简单地使用以下内容:

\makeatletter
\newlength\mywidth
\settowidth{\mywidth}{\ }
\def\@chapapp{\hspace*{-\mywidth}}
\makeatother

现在您的 MWE 可以更新为:

\documentclass[letterpaper,12pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage[spanish]{layout}
\usepackage{graphics,graphicx}
\usepackage[bottom=2.5cm,top=3cm,left=1.8cm,right=1.8cm,footnotesep=0.5cm]{geometry} % ,showframe
\usepackage[flushmargin]{footmisc}
\usepackage{blindtext}

\makeatletter
\newlength\mywidth
\settowidth{\mywidth}{\ }
\def\@chapapp{\hspace*{-\mywidth}}
\makeatother
\addtolength{\footnotesep}{2.5mm}
\renewcommand{\thefootnote}{\textbf{\arabic{footnote}}}

\begin{document}

\begin{titlepage}
    \centering
    %\includegraphics[width=6cm]{pics/logo.png}
    \par\vspace{1cm}
    {\scshape\LARGE Company's shortname\par}
    \par\vspace{1cm}
    {\scshape\LARGE Manual de Usuario \par}
    \par\vspace{1cm}
    {\scshape\Large Company's name \par}
    \vfill
    {\scshape My name ;) \par}
    \today \par
\end{titlepage}

\frontmatter
\tableofcontents

%\include{./TeX_files/intro}
\mainmatter
%\include{./TeX_files/primeros_pasos}
%\include{./TeX_files/cap_actas}
%\include{./TeX_files/cap_fotos}
\chapter{This is a chapter}
Some filler text here... \footnote{This is the footnote.}

\blindtext

\blindtext

\blindtext

\blindtext

\blindtext

\blindtext


\backmatter
% bibliography, glossary and index would go here.

\end{document}

注意:我添加了\blindtext来自包的命令blindtext来获取一些虚拟文本。您还可以使用 MWE 中使用的定义,例如将章节编号和章节标题打印在两行中。

输出:

在此处输入图片描述

相关内容