章节号位于名称上方且居中 - 未正确居中

章节号位于名称上方且居中 - 未正确居中

对这个感到困惑..

我想要这样的东西:在此处输入图片描述

但是使用下面的 MWE 我得到了这个 在此处输入图片描述

(暂时忽略字体和颜色的变化)

MWE 是

\documentclass[a4paper,10pt,twoside,onecolumn,openright,final,extrafontsizes]{memoir}

\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\definecolor{P548}{RGB}{0,65,86}
\usepackage{titlesec}
\titleformat{\chapter}[block]{\Huge\bfseries\color{P548}\filcenter}{\chaptertitlename\ \thechapter\newline}{1em}{}[\titlerule]

\begin{document}
    
    \chapter{My Chapter}
    
    Boom shackalack eget purizzle. Away sizzle amet diam boom shackalack massa we gonna chung pellentesque. Away et erizzle. Vivamus fizzle sapien, lacinia break yo neck, yall, vulputate daahng dawg, condimentum its fo rizzle, nunc. Cras sit shit maurizzle. 

\end{document}

答案1

试试这个代码:

\documentclass[a4paper,10pt,twoside,onecolumn,openright,final,extrafontsizes]{memoir}

\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\definecolor{P548}{RGB}{0,65,86}
\usepackage{titlesec,lipsum,emptypage}
\titleformat{\chapter}[display]{\Huge\bfseries}{\color{P548}\centering{\chaptertitlename \thechapter}}{-2pt}{\color{P548}\Huge\center}

\begin{document}
    
    \chapter{My Chapter}
    
    Boom shackalack eget purizzle. Away sizzle amet diam boom shackalack massa we gonna chung pellentesque. Away et erizzle. Vivamus fizzle sapien, lacinia break yo neck, yall, vulputate daahng dawg, condimentum its fo rizzle, nunc. Cras sit shit maurizzle. 
    
\end{document}

输出:

在此处输入图片描述

答案2

请注意titlesec与 并不真正兼容memoir

您的代码的问题在于block而不是display

\documentclass[a4paper,10pt,twoside,onecolumn,openright,final,extrafontsizes]{memoir}

\usepackage{xcolor}
\usepackage{titlesec}

\definecolor{P548}{RGB}{0,65,86}

\titleformat{\chapter}[display]
  {\Huge\bfseries\color{P548}\filcenter}
  {\chaptertitlename\ \thechapter}{2ex}
  {}
  [\vspace{2ex}\titlerule]

\begin{document}

\chapter{My Chapter}

Boom shackalack eget purizzle. Away sizzle amet diam boom
shackalack massa we gonna chung pellentesque. Away et
erizzle. Vivamus fizzle sapien, lacinia break yo neck,
yall, vulputate daahng dawg, condimentum its fo rizzle,
nunc. Cras sit shit maurizzle.

\end{document}

调整垂直间距以满足您的需要,但避免结合使用memoirtitlesec。 中有多种工具可用于重新定义章节样式memoir

在此处输入图片描述

相关内容