![章节号在“章节”后面怎么写](https://linux22.com/image/318390/%E7%AB%A0%E8%8A%82%E5%8F%B7%E5%9C%A8%E2%80%9C%E7%AB%A0%E8%8A%82%E2%80%9D%E5%90%8E%E9%9D%A2%E6%80%8E%E4%B9%88%E5%86%99.png)
我想在“章节”一词后面写上章节编号,但遇到了以下问题。
- 号码写成在前'CHAPTER'(我希望它位于后面——红色位于蓝色后面)
- 我曾使用 raisebox 和 makebox 来定位数字,但在定位数字时遇到了问题中心位于‘CHAPTER’后面。
有问题的情况如下所示。
\documentclass{memoir}
\usepackage{graphicx}
\graphicspath{{graphics/}}
\usepackage{tikz}
\newcommand\numlifter[1]{\raisebox{0.6cm}[0pt][0pt]{\smash{#1}}}
\newcommand\numindent{\kern37pt}
\newlength\chaptertitleboxheight
\makeatletter
\makechapterstyle{mychapterstyle}{
\chapterstyle{default}
\def\format{\normalfont}
\setlength\beforechapskip{0mm}
\renewcommand*{\chapnamefont}{\format\small}
\renewcommand*{\chapnumfont}{\format\HUGE}
\renewcommand*{\chaptitlefont}{\format\Huge}
\renewcommand*{\printchaptername}{\chapnamefont\MakeUppercase{\@chapapp}}
\patchcommand{\printchaptername}{\begingroup\color{blue}}{\endgroup}
\renewcommand\printchapternum{%
\begingroup%
\leavevmode%
\chapnumfont%
\color{red}%
\itshape
\strut%
\numlifter{\makebox[\linewidth][l]{\thechapter}}
\numindent%
\endgroup%
}
\setlength\midchapskip{1ex}
\renewcommand*{\printchaptertitle}[1]{\raggedleft \chaptitlefont ##1}
\renewcommand*{\afterchaptertitle}{\vskip0.5\onelineskip \hrule \vskip1.3\onelineskip}
}
\makeatother
\chapterstyle{mychapterstyle}
\begin{document}
\chapter{foo}
Hi everyone :)
\end{document}
答案1
章节名称字符串后面居中的数字
\documentclass{memoir}
\usepackage{graphicx}
\graphicspath{{graphics/}}
\usepackage{tikz}
\newcommand\numlifter[1]{\raisebox{0.6cm}[0pt][0pt]{\smash{#1}}}
\newcommand\numindent{\kern37pt}
\newlength\chaptertitleboxheight
\makeatletter
\makechapterstyle{mychapterstyle}{%
\chapterstyle{default}%
\def\format{\normalfont}%
\setlength\beforechapskip{0mm}%
\renewcommand*{\chapnamefont}{\format\small}%
\renewcommand*{\chapnumfont}{\format\HUGE}%
\renewcommand*{\chaptitlefont}{\format\Huge}%
\renewcommand*{\printchaptername}{%
\textcolor{blue}{\chapnamefont\MakeUppercase{\@chapapp}}%
}%
\renewcommand*{\printchaptername}{%
\sbox0{%
\color{blue}%
\chapnamefont
\MakeUppercase{\@chapapp}%
}%
\sbox2{%
\color{red}%
\chapnumfont
\itshape
\thechapter
}%
\leavevmode
\rlap{%
\hbox to \wd0{%
\hfill
\raisebox{\dimexpr.5\ht0 - .5\ht2\relax}{\usebox{2}}%
\hfill
}%
}%
\usebox{0}%
}%
\renewcommand*{\printchapternum}{}%
\renewcommand*{\chapternamenum}{}%
\setlength\midchapskip{1ex}%
\renewcommand*{\printchaptertitle}[1]{\raggedleft \chaptitlefont ##1}%
\renewcommand*{\afterchaptertitle}{%
\vskip0.5\onelineskip
\hrule
\vskip1.3\onelineskip
}%
}
\makeatother
\chapterstyle{mychapterstyle}
\begin{document}
\chapter{foo}
Hi everyone :)
\end{document}
旧版本名称后面带有数字
\documentclass{memoir}
\usepackage{graphicx}
\graphicspath{{graphics/}}
\usepackage{tikz}
\newcommand\numlifter[1]{\raisebox{0.6cm}[0pt][0pt]{\smash{#1}}}
\newcommand\numindent{\kern37pt}
\newlength\chaptertitleboxheight
\makeatletter
\makechapterstyle{mychapterstyle}{%
\chapterstyle{default}%
\def\format{\normalfont}%
\setlength\beforechapskip{0mm}%
\renewcommand*{\chapnamefont}{\format\small}%
\renewcommand*{\chapnumfont}{\format\HUGE}%
\renewcommand*{\chaptitlefont}{\format\Huge}%
\renewcommand*{\printchaptername}{%
\textcolor{blue}{\chapnamefont\MakeUppercase{\@chapapp}}%
}%
\renewcommand*{\printchapternum}{%
\sbox0{\chapnamefont CHAPTER}%
\sbox2{%
\color{red}%
\chapnumfont
\itshape
\thechapter
}%
\raisebox{\dimexpr.5\ht0 - .5\ht2\relax}{\copy2}%
}%
\setlength\midchapskip{1ex}%
\renewcommand*{\printchaptertitle}[1]{\raggedleft \chaptitlefont ##1}%
\renewcommand*{\afterchaptertitle}{%
\vskip0.5\onelineskip
\hrule
\vskip1.3\onelineskip
}%
}
\makeatother
\chapterstyle{mychapterstyle}
\begin{document}
\chapter{foo}
Hi everyone :)
\end{document}
免责声明:布局不符合我的口味:
- 颜色太多了。
- 字体大小过多。
- 没有明确基线。
- 全部大写。
我建议简化布局,这通常会更好。
答案2
如果您可以使用tikz
,那就非常容易了。
\documentclass{memoir}
\usepackage{graphicx}
\graphicspath{{graphics/}}
\usepackage{tikz}
\makeatletter
\makechapterstyle{mychapterstyle}{
\chapterstyle{default}
\def\format{\normalfont}
\setlength\beforechapskip{0mm}
\renewcommand*{\chapnamefont}{\format\small}
\renewcommand*{\chapnumfont}{\format\HUGE}
\renewcommand*{\chaptitlefont}{\format\Huge}
\renewcommand*{\printchaptername}{%
\begin{tikzpicture}
\node[text=red,font=\chapnumfont\itshape] (a){\thechapter};
\node[text=blue,font=\chapnamefont] at (a.center){\MakeUppercase{\@chapapp}};
\end{tikzpicture}%
}
\renewcommand\printchapternum{}
\setlength\midchapskip{1ex}
\renewcommand*{\printchaptertitle}[1]{\raggedleft \chaptitlefont ##1}
\renewcommand*{\afterchaptertitle}{\vskip0.5\onelineskip \hrule \vskip1.3\onelineskip}
}
\makeatother
\chapterstyle{mychapterstyle}
\begin{document}
\chapter{foo}
Hi everyone :)
\end{document}