章节和其名称不在同一行

章节和其名称不在同一行

抱歉,我说得不清楚。

我是 LaTeX 初学者,一直在努力将章节名称及其编号放在章节所在的同一行。应该是这样的:

在此处输入图片描述

代码本身由我修改以符合大学要求。使用的类是报告,但使用经过修改的“Rackham”样式(我猜是密歇根大学)。

最小工作代码是 MS Thesis.tex:

% The packages used here are just a sample. You may need others, and may not need some of these.
% A style was adopted from Rachkam style that can be found in internet
\documentclass[12pt,oneside]{report} % right-side equation numbering, 12 point font, print one-sided 
\usepackage{csm}         % Use the following thesis style file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\bibliographystyle{humanbio}

\titlepage{The Title of Your Dissertation}{Your Name}

% Begin the front matter 
\initializefrontsections

\startabstractpage

Here is a brief explanation of thesis goes. 

% Table of contents, list of figures, etc.
\tableofcontents     % Required
\listoffigures       % Required if there is more than one figure
\listoftables        % Required if there is more than one table
\listofsymbols       % Required if there is more than one equation 

% Optional Acknowledgements page
\startacknowledgementspage
%\input{Intro/Acknowledgements}
\label{Acknowledgements}

\startthechapters 

 \chapter{Introduction}
This chapter disccuses an importance of converting public transportation to renewable energy sources. 
 \label{chap:Intro}

\section{Motivation}
The traditional  petroleum based fuels like gasoline is, first of all, ecologically unsafe. 

\section{Objectives}
Alternative energy sources such as electric batteries can ecomically be installed in the public transportation and used. 

\section{Methodology}

 \chapter{Background and Literature Review}

\chapter{Transporation Fees}
\section{the cost of public transportation in big cities}

\end{document}

下面的样式代码很长,但会产生下面的目录外观(样式代码之后)。

% The 'csm' style, which is called by \usepackage{csm} in the main code
\typeout{  }
\typeout{Substyle `rac' for Rackham dissertation.}
\typeout{  }

%-- Page styles --

\def\ps@chappage{% The first page of each chapter has bottom-center page numbers
 \def\@oddhead{}
 \def\@oddfoot{\hfil \rm \thepage \hfil}
 \let\@evenhead\@oddhead 
 \let\@evenfoot\@oddfoot
}

\def\ps@plain{%
% \def\@oddhead{\hfil \rm \thepage \hfil} % These two lines of code make top-center page numbers on other pages
% \def\@oddfoot{}
 \def\@oddhead{} % These two lines of code make bottom-center page numbers on other pages
 \def\@oddfoot{\hfil \rm \thepage \hfil}
 \let\@evenhead\@oddhead 
 \let\@evenfoot\@oddfoot
}

%-- Margins --
\if@twoside \oddsidemargin 0.5in \evensidemargin 0in \marginparwidth .6in \textheight=8.95in
\else \oddsidemargin 0.5in \marginparwidth .9in \textheight=9.0in\fi% left margin=1in + oddsidemargin, marginparwidth: text box for margin notes
\topmargin -0.65in \headheight 0.35in \headsep 0.35in \footskip 0.5in % header and footer margins
\textwidth=6.0in % width of the text body on a page
% The top margin = 1in plus vspace. For some reason, need to subtract 0.35in also.
\def\vertadjust{\vspace{-0.35in}} % Required for proper vertical spacing.
\def\twoinmar{\vertadjust\vspace{0.25in}} % Two inch top margin
\def\twohalfinmar{\vertadjust\vspace{1.5in}} % Two and a half inch top margin

%-- Front pages --

% This \ttlpg is the same as \titlepage in report.sty.
\def\ttlpg{\@restonecolfalse \if@twocolumn \@restonecoltrue \onecolumn
 \else \newpage \fi \thispagestyle{empty} \c@page \z@}

\def\titlepage#1#2{
 \ttlpg
 \begin{singlespace}
 \hbox{ }
 \twohalfinmar
 \begin{center}
 \begin{onehalfspacing} % For the `Large' font size, this will look single spaced.
\vspace{2in}  
  {\Large\MakeUppercase{#1} \mbox{}} \\
 \end{onehalfspacing}
  \vfill
  by \\
  \vspace{2ex} % ex is the height of the lowercase 'x' for the current font.
  #2 \\
 \end{center}
 \end{singlespace}
}

\def\initializefrontsections{
 \setcounter{page}{1}   % -- begins with "ii"
 \pagestyle{chappage}   % -- numbers at bottom
 \renewcommand{\thepage}{\roman{page}}   % roman numeral
}

%  ABSTRACT 
\def\startabstractpage{
 \newpage
 \twoinmar
 \addcontentsline{toc}{chapter}{ABSTRACT}
 \hbox{ }
 \twoinmar
 \centerline{\large\bf ABSTRACT}
 \vspace{0.25in}
}

\def\startacknowledgementspage{
 \newpage
 \addcontentsline{toc}{chapter}{ACKNOWLEDGEMENTS}
 \hbox{ }
 \twoinmar
 \centerline{\large\bf ACKNOWLEDGEMENTS}
 \vspace{0.25in}
}

%-- Table of contents and lists --

\def\dotfill{\leaders\hbox{$\m@th \mkern \@dotsep mu.\mkern \@dotsep mu$}\hfill}
\def\producetableofcontents{\tableofcontents}
\def\producelistoffigures{\listoffigures}
\def\producelistoftables{\listoftables}
\def\producelistofmaps{\listofmaps}
\def\producelistofappendices{\listofappendices}
\def\producelistofabbreviations{\listofabbreviations}

% The only difference is \dotfill instead of \hfil.
\def\l@chapter#1#2{\pagebreak[3]
 \vskip 1.0em plus 1pt \@tempdima 1.5em \begingroup 
 \parindent \z@ \rightskip \@pnumwidth
 \parfillskip -\@pnumwidth
 {\leavevmode #1}\dotfill \hbox to\@pnumwidth{\hss #2}\par
 \endgroup
}

\def\l@chap{\@dottedtocline{1}{1.0em}{1.5em}}
\def\l@section{\@dottedtocline{2}{2.5em}{3.0em}}
\def\l@subsection{\@dottedtocline{3}{5.5em}{3.0em}}
\def\l@subsubsection{\@dottedtocline{4}{8.5em}{3.0em}}

\setcounter{tocdepth}{3} % Number of section layers to show in TOC (i.e. section, subsection, subsubsection)
\setcounter{secnumdepth}{3} % Number of subsection layers to allow in document

\def\l@figure{\@dottedtocline{1}{1.0em}{3.5em}}
\let\l@table\l@figure
\let\l@map\l@figure
\let\l@anything\l@figure
\def\l@appendix{\@dottedtocline{1}{1.0em}{2.5em}}
\let\l@abbreviation\l@figure

\def\tableofcontents{%
 \newpage
 \@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn\fi
 \hbox{ }
 \twoinmar
 \centerline{\large\bf TABLE OF CONTENTS}
 \vspace{0.25in}
 \begin{onehalfspace}
  \@starttoc{toc}\if@restonecol\twocolumn\fi
 \end{onehalfspace} 
}

\def\listoffigures{%
 \newpage
 \addcontentsline{toc}{chapter}{LIST OF FIGURES}
 \@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn\fi
 \hbox{ }
 \twoinmar
 \centerline{\large\bf LIST OF FIGURES}
 \vspace{0.25in}
 \begin{onehalfspace}
  \@starttoc{lof}\if@restonecol\twocolumn\fi
  \addtocontents{lof}{\noindent\underline{\bf Figure}\hfill\rm\protect\newline}
 \end{onehalfspace}
}

\def\listoftables{%
 \newpage
 \addcontentsline{toc}{chapter}{LIST OF TABLES}
 \@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn\fi
 \hbox{ }
 \twoinmar
 \centerline{\large\bf LIST OF TABLES}
 \vspace{0.25in}
 \begin{onehalfspace}
  \@starttoc{lot}\if@restonecol\twocolumn\fi
  \addtocontents{lot}{\noindent\underline{\bf Table}\hfill\rm\protect\newline}
 \end{onehalfspace}
}

% Creating the list of symbols to appear in the thesis
% Created similarly to the abbreviations list
\def\listofsymbols{
 \newpage
 \addcontentsline{toc}{chapter}{LIST OF SYMBOLS}
 \@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn\fi
 \hbox{ }
 \twoinmar
 \centerline{\large\bf LIST OF SYMBOLS}
 \vspace{0.25in}
 \begin{onehalfspace}
   %\input{symbols}
 \end{onehalfspace} 
}

%-- Start chapters --

\def\thechapter {\@arabic\c@chapter}
\def\thesection {\@arabic\c@chapter.\@arabic\c@section}
\def\thefigure {\@arabic\c@chapter.\@arabic\c@figure}
\def\thetable {\@arabic\c@chapter.\@arabic\c@table}
\def\theequation {\@arabic\c@chapter.\@arabic\c@equation}

\newcounter{map}[chapter]
\def\themap{\@arabic\c@chapter.\@arabic\c@map}
\def\fps@map{tbp}
\def\ftype@map{1}
\def\ext@map{lom}
\def\fnum@map{Map \themap}
\def\map{\@float{map}}
\let\endmap\end@float
\@namedef{map*}{\@dblfloat{map}}
\@namedef{endmap*}{\end@dblfloat}

\def\startthechapters{%
 \def\@chapapp{CHAPTER}
 \addtocontents{toc}{\protect\mbox{ }\protect\newline\noindent{CHAPTER}\protect\newline}
 \addtocontents{toc}{\hbox{ }}
 \clearpage % This has to be before the rest.
 \if@twoside \ifodd\c@page \else \ttlpg \hbox{ }\fi\fi % For two-sided printing, make sure Chapter I starts on right-hand page. jg
 \clearpage
 \setcounter{chapter}{0}
 \setcounter{page}{1} % -- ...always begin with ii.
 \renewcommand{\thepage}{\arabic{page}}
 \pagestyle{plain}
 \def\tocname{toc}
}

\def\@chapter[#1]#2{%
 \ifnum \c@secnumdepth >\m@ne
  \refstepcounter{chapter}
  \typeout{\@chapapp\space\thechapter.}
  \addtocontents{toc}{\hbox{ }}
  \addcontentsline{toc}{chap}{\protect\numberline{\hbox{ }\hfill\thechapter.\hspace{5pt}}{\MakeUppercase{#1}}}
  \addtocontents{toc}{\hbox{ }}
 \else
  \addtocontents{toc}{\hbox{ }}
  \addcontentsline{toc}{chap}{#1}
  \addtocontents{toc}{\hbox{ }}
 \fi
 \if@twocolumn \@topnewpage[\@makechapterhead{#2}]
 \else \@makechapterhead{#2} \@afterheading \fi
}

\def\@makechapterhead#1{%
 \hbox{ }
 \twoinmar
 {\parindent 0pt \raggedright
  \ifnum \c@secnumdepth >\m@ne
  \centerline{\large\bf \@chapapp{} \thechapter} \par
  \vskip 0in \fi
  \begin{center}
   \centerline{\MakeUppercase{\large\bf #1}}
   %\large\bf #1
  \end{center}
  \nobreak
 }
 \@afterindenttrue
}

\def\section{\@startsection{section}{1}{\z@}{3.25ex plus 1ex minus
 .2ex}{2.3ex plus .2ex}{\normalsize\bf}}
\def\subsection{\@startsection{subsection}{2}{\z@}{3.25ex plus 1ex minus
 .2ex}{1.3ex plus .2ex}{\normalsize\bf}}
\def\subsubsection{\@startsection{subsubsection}{3}{\z@}{3.25ex plus
 1ex minus .2ex}{1.3ex plus .2ex}{\normalsize\bf}}

在此处输入图片描述

由于我将其缩短以发布在此处,因此代码可能会给出一些警告。建议按回车键。

答案1

您的图片显示章节编号和标题打印在一行上

  1. 介绍

这个数字不是以 CHAPTER 开头的,我们可以修复,但首先有一个完全虚假的

章节

在目录的开头,由\startthechapters以下命令写入

\addtocontents{toc}{\protect\mbox{ }\protect\newline\noindent{CHAPTER}\protect\newline}

 \addtocontents{toc}{\hbox{ }}

应将其删除。

章节目录行由

% The only difference is \dotfill instead of \hfil.
\def\l@chapter#1#2{\pagebreak[3]
 \vskip 1.0em plus 1pt \@tempdima 1.5em \begingroup 
 \parindent \z@ \rightskip \@pnumwidth
 \parfillskip -\@pnumwidth
 {\leavevmode\@chapapp\ #1}\dotfill \hbox to\@pnumwidth{\hss #2}\par
 \endgroup
}

\@chapapp我在前面添加了,#1所以它会根据上下文写出章节或附录

相关内容