我想以某种方式对齐章节标题:未编号的标题应居中;编号的标题应左对齐并缩进。我只是想编写一个例子
\documentclass[12pt,a4paper,oneside]{article}
\usepackage[left=35mm,right=15mm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[russian]{babel}
\usepackage{cmap}
\usepackage{makeidx}
\makeindex
\usepackage{indentfirst}
\setlength{\parindent}{1.25cm}
\usepackage{setspace}
\onehalfspacing
\usepackage{titlesec}
\titleformat{\section*}{\normalfont\Large\bfseries\justifyheading}{\thesection}{1em}{}
\begin{document}
\section*{РЕФЕРАТ}
\end{document}
但我越来越
! Missing \endcsname inserted.
! LaTeX Error: Missing \begin{document}.
! Extra \endcsname.
! Argument of \ttl@assign@i has an extra }.
! Paragraph ended before \ttl@assign@i was complete.
! Package keyval Error: \let \reserved@d =*\def \par .
! Missing \endcsname inserted.
! Missing number, treated as zero.
! Illegal unit of measure (pt inserted).
! Undefined control sequence.
! Missing number, treated as zero.
! Illegal unit of measure (pt inserted).
! Extra \endcsname.
! Undefined control sequence.
! Too many }'s.
! LaTeX Error: Command \CYRA unavailable in encoding OT1.
是的,有没有办法只对齐部分而不重新定义整个样式?我应该使用\newcommand
并将其插入到每个部分吗?
答案1
没有\justifyheading
命令;您可以改用\filcenter
;由于不同的格式将应用于编号和未编号部分,因此您可以将name=\section,numberless
的第一个参数中的选项\titleformat
用于未编号部分,而仅\section
用于编号部分。该explicit
选项用于明确访问标题并轻松实现编号部分所需的缩进:
\documentclass[12pt,a4paper,oneside]{article}
\usepackage[left=35mm,right=15mm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}
\usepackage[utf8x]{inputenc}
\usepackage[russian]{babel}
\usepackage{cmap}
\usepackage{makeidx}
\makeindex
\usepackage{indentfirst}
\setlength{\parindent}{1.25cm}
\usepackage{setspace}
\onehalfspacing
\usepackage[explicit]{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}{}{0em}{\hspace{1.25cm}\thesection\hspace{1em}#1}% numbered sections
\titleformat{name=\section,numberless}
{\normalfont\Large\bfseries\filcenter}{}{0em}{#1} % unnumbered sections
\usepackage{lipsum} % just to generate text
\begin{document}
\section*{РЕФЕРАТ}
\section{РЕФЕРАТ}
\lipsum[1-2]
\end{document}