使用 \renewcommand 格式化章节标题

使用 \renewcommand 格式化章节标题

我尝试使用命令使我的部分显示为“部分 I:我的部分标题”或“部分 I 我的部分标题”,\renewcommand\thesection...但在目录中,“部分”一词未出现在正确的位置。它看起来像这样:

在此处输入图片描述

这是我的 MWE:

\documentclass[12pt,a4paper]{article}
\usepackage[utf8x]{inputenc}
\usepackage{ucs}
\usepackage[francais]{babel}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathptmx}
\usepackage{amssymb}
\usepackage[left=1cm,right=1cm,top=1.5cm,bottom=1.5cm]{geometry}
\title{my title}
\renewcommand\thesection{Section \ \Roman {section}}
\begin{document}
\maketitle
\tableofcontents
\pagebreak
\section{my section}
\end{document}

提前感谢您的帮助。

答案1

如果您只想在目录中执行此操作,则可以使用包tocloft。如果您还想在文本中包含“Section”一词,则可以使用包titlesec

\documentclass[12pt,a4paper]{report}

\usepackage{tocloft}
\renewcommand{\cftsecpresnum}{Section }
\renewcommand{\cftsecnumwidth}{6em}
\renewcommand{\thesection}{\Roman{section}}

\usepackage{titlesec}
\titleformat{\section}{\large\bfseries}{}{0pt}{Section \thesection\quad}

\title{my title}

\begin{document}
\maketitle
\tableofcontents
\pagebreak
\chapter{First chapter}
\section{my section}
\subsection{my section}
\subsection{my section}
\section{another section}
\chapter{Second chapter}
\section{my section}
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容