问题

问题

首先,我一直在网上搜索,也发现了类似的案例,但对我的问题没有任何帮助,而且我对 LaTeX 还很陌生。

问题

  • 如果我从中去掉数字\section,那么每个部分的子部分编号都是相同的(这是在内容本身中)。

                                  Centered Section Title
    1  Subsection
       1.1 Subsubsection
       1.2 Subsubsection
                                   Other Section Title
    1  Subsection
       1.1 Subsubsection
       1.2 Subsubsection
    
  • 目录中也一样,但各部分向右移动。以 [] 表示:

                            Index
    
    Introduction (manually added)......................xx
    [ ]Section Title...................................xx
    [ ]1  Subsection...................................xx
    [ ]   1.1 Subsubsection............................xx
    [ ]   1.2 Subsubsection............................xx
    [ ]Other Section Title.............................xx
    [ ]1  Subsection...................................xx
    [ ]   1.1 Subsubsection............................xx
    [ ]   1.2 Subsubsection............................xx
    Bibliography (manually added)......................xx
    

我想要的是

  • 我需要获取标题和目录中没有数字的部分,但\subsection必须\subsubsection有该编号。

                                  Centered Section Title
    1.1  Subsection
       1.1.1 Subsubsection
       1.1.2 Subsubsection
                                   Other Section Title
    2.1  Subsection
       2.1.1 Subsubsection
       2.1.2 Subsubsection
    
  • 获取目录中对齐的部分。

如果我写错了,我很抱歉,英语不是我的母语

我当前的代码:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{\thesection}{0em}{\Large\bfseries}
    \renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections

% to fill TOC with dots
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill\hfill}%center TOC title

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document}

答案1

我不建议在章节标题中硬编码“Capítulo 1: First Things”之类的内容。以下代码看起来有点笨重,因为它执行的操作超出了您的要求,但它会生成更多的 LaTeXnish 手稿文件。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[spanish,activeacute]{babel}
\usepackage{tocloft}
  \renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
  \renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
  \renewcommand{\cftaftertoctitle}{\hfill\hfill}

\makeatletter
\renewcommand\section{\secdef\@section\@ssection}
\def\@section[#1]#2{%
  \ifnum \c@secnumdepth >\@ne
    \refstepcounter{section}%
    \typeout{\sectionname\space\thesection.}%
    \addcontentsline{toc}{section}%
                    {\protect#1}%
  \else
    \addcontentsline{toc}{section}{#1}%
  \fi
  \sectionmark{#1}%
  \if@twocolumn
    \@topnewpage[\@makesectionhead{#2}]%
  \else
    \@makesectionhead{#2}%
    \@afterheading
  \fi}
\def\@makesectionhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering \normalfont
    \ifnum \c@secnumdepth >\@ne
      \interlinepenalty\@M
      \Large\bfseries \sectionname\space \thesection: #1\par\nobreak
    \fi
    \vskip 10\p@}}%
\def\@ssection#1{%
  \if@twocolumn
    \@topnewpage[\@makessectionhead{#1}]%
  \else
    \@makessectionhead{#1}%
    \@afterheading
  \fi}%
\def\@makessectionhead#1{%
  \vspace*{10\p@}%
  {\parindent \z@ \centering\normalfont
    \interlinepenalty\@M
    \Large \bfseries  #1\par\nobreak
    \vskip 10\p@}}%
\def\sectionname{Section}
\makeatother

\setcounter{secnumdepth}{3}
\addto\captionsspanish{%
  \renewcommand{\contentsname}{Indice General}
  \renewcommand{\sectionname}{Sección}}% or Capítulo of course...

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section{First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Title for section}
\subsection{Algo}
\subsubsection{Algo más}
\end{document}

输出

答案2

您可以使用包来titletoc代替tocloft来实现您想要的。

首先,忘记重新定义\thesection,也就是删除这些行

\renewcommand{\thesection}{}% Remove section references...
\renewcommand{\thesubsection}{\arabic{subsection}}%... from subsections

然后删除其中的内容tocloft并添加以下几行:

\usepackage{titletoc}
\titlecontents{section}
              [0em]
              {\addvspace{1pc}\bfseries}
              {}
              {}
              {\mdseries\titlerule*[.75pc]{.}\bfseries\contentspage}

结果如下:

在此处输入图片描述

完整代码:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{}{0em}{\Large\bfseries}

\usepackage{titletoc}
\titlecontents{section}
              [0em]
              {\addvspace{1pc}\bfseries}
              {}
              {}
              {\mdseries\titlerule*[.75pc]{.}\bfseries\contentspage}

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document} 

编辑

根据您的评论,要使用罗马数字来表示目录中的章节(尽管我不赞成这种选择),请执行以下操作。

声明\thesection\Roman\thesubsection\arabic

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}

在这种情况下,最好使用tocloft而不是titletoc

在原始设置中添加以下几行:

\cftsetindents{section}{0em}{3em}
\cftsetindents{subsection}{3em}{2.3em}
\cftsetindents{subsubsection}{5.3em}{3em}

结果如下:

在此处输入图片描述

请注意,罗马数字和标题之间的间距故意留得很大,以便为大数字留出空间。

完整代码:

\documentclass[12pt]{article}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[spanish,activeacute]{babel}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{amsmath,amsthm}
\usepackage[left=1.58in,right=0.98in,top=0.5in,bottom=0.5in]{geometry}

%to do not put numbers in sections
\usepackage{titlesec}
\titleformat{\section}{\centering}{}{0em}{\Large\bfseries}

\renewcommand{\thesection}{\Roman{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}

% to fill TOC with dots
\usepackage{tocloft}
\renewcommand{\cftsecleader}{\cftdotfill{\cftdotsep}}
\renewcommand{\cfttoctitlefont}{\hfill\Large\bfseries}
\renewcommand{\cftaftertoctitle}{\hfill\hfill}%center TOC title
\cftsetindents{section}{0em}{3em}
\cftsetindents{subsection}{3em}{2.3em}
\cftsetindents{subsubsection}{5.3em}{3em}

%to replace TOC title
\addto\captionsspanish{
  \renewcommand{\contentsname}{Indice General}
}

\setcounter{secnumdepth}{3}

\begin{document}
\tableofcontents

\section*{Introduction}
\addcontentsline{toc}{section}{Introduction}
\paragraph{About:} Some text over here...

\section[First Things]{Capítulo 1: First Things}
\subsection{Algo}
\subsubsection{Algo más}

\section[Title for TOC]{Capítulo 2: Title for section}
\subsection{Algo}
\subsubsection{Algo más}

\section[Again for TOC]{Capítulo 3: Title for Text}

\section[Conclutions]{Conclutions}

\clearpage
\addcontentsline{toc}{section}{Bibliography}
% Bibliography.
\begin{thebibliography}{99}
\bibitem{Someone}
\emph{...}.
\end{thebibliography}
\end{document} 

相关内容