我想更改章节格式,包括上下行和右对齐文本,如下图所示,而不使用titlesec
包:
这是我的代码:
\documentclass[a4paper,openright,12pt]{report}
\usepackage[utf8]{inputenc}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{0\p@}%
{\parindent \z@ \raggedright \normalfont
\ifnum \c@secnumdepth >\m@ne
\huge\bfseries
% \@chapapp\space % removed
\thechapter
\nobreakspace{}% \par\nobreak\vskip 20\p@ % replaced
\fi
\interlinepenalty\@M
\huge % \Huge % replaced
\bfseries #1\par\nobreak
\vskip 25\p@
}}
\makeatother
\begin{document}
\chapter{Chapter}
\end{document}
在序言中,该代码是为了将章节格式从“第 1 章 \\ 章节标题”更改为“1. 章节标题”。
有人知道如何添加线条并将文本右对齐,如上图所示吗?谢谢。
答案1
和\hrule
。
\documentclass[a4paper,openright,12pt]{report}
\usepackage[utf8]{inputenc}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{0\p@}
\hrule\ \\
{\parindent \z@ \raggedleft \normalfont
\ifnum \c@secnumdepth >\m@ne
\huge\bfseries
% \@chapapp\space % removed
\thechapter
\nobreakspace{}% \par\nobreak\vskip 20\p@ % replaced
\fi
\interlinepenalty\@M
\huge % \Huge % replaced
\bfseries #1\par\nobreak
\vskip 10\p@
\hrule
}}
\makeatother
\begin{document}
\chapter{Chapter}
\end{document}
和\rule
。
\documentclass[a4paper,openright,12pt]{report}
\usepackage[utf8]{inputenc}
\makeatletter
\def\@makechapterhead#1{%
\vspace*{0\p@}
\noindent\rule{\textwidth}{2pt}\\
{\parindent \z@ \raggedleft \normalfont
\ifnum \c@secnumdepth >\m@ne
\huge
% \@chapapp\space % removed
\thechapter
\nobreakspace{}% \par\nobreak\vskip 20\p@ % replaced
\fi
\interlinepenalty\@M
\normalfont % \Huge % replaced
\ #1\par\nobreak
\vskip 0\p@
\noindent\rule{\textwidth}{2pt}
}}
\makeatother
\begin{document}
\chapter{Chapter}
\end{document}