章节标题样式

章节标题样式

在以下 MWE 中定义的章节标题样式中,章节标题的文本与章节号的顶部对齐(参见第一张图片)。参见Schweinebacke 的答案章节标题样式了解有关该风格的更多信息。

对于多行标题,这很好,但是对于单行标题,我想将章节标题相对于章节号居中(请参阅第二张图片以了解所需结果)。因此,我需要根据章节标题的行数进行不同的对齐。章节号和垂直线保持在同一位置,标题对齐在数字的中心,而不是章节号的顶部。

有人可以帮忙吗?

\documentclass{scrreprt}

\usepackage[      
                  includemp,
                  showframe,
                  showcrop,
                  reversemp,
            paper=a4paper,
            layoutwidth=20.1cm,
            layoutheight=25.8cm,
            layoutvoffset=19.5mm,
            layouthoffset=4.5mm,
            top=2.30cm,
            bottom=3.4cm,
            inner=2cm,
            outer=2cm,
            marginparwidth=1.6cm, % Fixed for now
            marginparsep=0.4cm
            ]{geometry}

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\usepackage{graphicx}


\usepackage{graphicx}
\renewcommand*{\chapterformat}{%
  \raisebox{-\ht\strutbox}[\ht\strutbox][\dp\strutbox]{% move the chapter   number down
    \makebox[0pt][r]{%
      \scalebox{2}{% double size the chapter number
        \chapappifchapterprefix{\ }\thechapter\autodot
      \hspace{0.05cm}\rule[-\dp\strutbox]{1pt}{\baselineskip}% add a rule behind the number
      }%
      \hskip\marginparsep
    }%
  }%
}%
\renewcommand*{\sectionformat}{\makebox[0pt][r]
{\thesection\autodot\hskip\marginparsep}}
\renewcommand*{\subsectionformat}{\makebox[0pt][r]
{\thesubsection\autodot\hskip\marginparsep}}
\renewcommand*{\subsubsectionformat}{\makebox[0pt][r]
{\thesubsubsection\autodot\hskip\marginparsep}}

% remove the vertical skip before the chapter heading
\RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}

\begin{document}

\chapter{Test}
\chapter{Test with a longer name, test with a longer name, test with a 
 longer name}
\section{test}
\section{test}

\end{document}

在此处输入图片描述

在此处输入图片描述

答案1

我会将可选参数更改为\rule-.75\dp\strutbox然后重新定义\chapterlinesformat

\documentclass{scrreprt}
\usepackage[
  includemp,
  showframe,
  reversemp,
  paperwidth=20.1cm,
  paperheight=25.80cm,
  top=2.30cm,
  bottom=3.4cm,
  inner=2.7cm,
  outer=2.7cm,
  marginparwidth=1.6cm, % Fixed for now
  marginparsep=0.4cm
]{geometry}
\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\usepackage{graphicx}
\renewcommand*{\chapterformat}{%
  \scalebox{2}{% double size the chapter number
    \chapappifchapterprefix{\ }\thechapter\autodot
    \hspace{0.5mm}\rule[-.75\dp\strutbox]{1pt}{\baselineskip}% add a rule behind the number
  }%
  \IfUsePrefixLine{}{\hskip\marginparsep}%
}

\renewcommand\chapterlinesformat[3]{%
\parbox{0pt}{\makebox[0pt][r]{#2}}\parbox{\linewidth}{\raggedchapter#3}%
}

\RedeclareSectionCommand[
  beforeskip=-1sp plus -1sp minus -1sp,% remove the vertical skip before the chapter heading
]{chapter}

\renewcommand*{\sectionformat}{\makebox[0pt][r]
  {\thesection\autodot\hskip\marginparsep}}
\renewcommand*{\subsectionformat}{\makebox[0pt][r]
  {\thesubsection\autodot\hskip\marginparsep}}
\renewcommand*{\subsubsectionformat}{\makebox[0pt][r]
  {\thesubsubsection\autodot\hskip\marginparsep}}

\begin{document}
\chapter{Test}
\chapter{Test with a longer name, test with a longer name,
  test with a longer name}
\section{test}
\section{test}
\chapter{Test with a longer name, test with a longer name,
  test with a longer name, test with a longer name}
\end{document}

在此处输入图片描述

在此处输入图片描述

答案2

您可以重新定义\chapterlinesformat将两个(默认)垂直居中的\parboxes 并排放置。

\documentclass{scrreprt}

\usepackage[      
  includemp,
  showframe,
  showcrop,
  reversemp,
  paper=a4paper,
  layoutwidth=20.1cm,
  layoutheight=25.8cm,
  layoutvoffset=19.5mm,
  layouthoffset=4.5mm,
  top=2.30cm,
  bottom=3.4cm,
  inner=2cm,
  outer=2cm,
  marginparwidth=1.6cm, % Fixed for now
  marginparsep=0.4cm
]{geometry}

\makeatletter          % to set the marginpar on the left side in showframe
\let\Gm@vrules@mpi\Gm@vrules@mpii
\makeatother

\usepackage{graphicx}
\renewcommand*{\chapterformat}{%
  \makebox[0pt][r]{%
    \scalebox{2}{% double size the chapter number
      \chapappifchapterprefix{\ }\thechapter\autodot
      \hspace{0.05cm}\rule[-\dp\strutbox]{1pt}{\baselineskip}% add a rule behind the number
    }%
    \hskip\marginparsep
  }%
}%
\newsavebox\chaptertitlebox
\renewcommand*{\chapterlinesformat}[3]{%
  \parbox{0pt}{\strut#2}% put the number in a vertically centered box
  \parbox{\linewidth}{\raggedchapter\strut\ignorespaces #3}% put the text in a vertically centered box
}
\renewcommand*{\sectionformat}{\makebox[0pt][r]
{\thesection\autodot\hskip\marginparsep}}
\renewcommand*{\subsectionformat}{\makebox[0pt][r]
{\thesubsection\autodot\hskip\marginparsep}}
\renewcommand*{\subsubsectionformat}{\makebox[0pt][r]
{\thesubsubsection\autodot\hskip\marginparsep}}

% remove the vertical skip before the chapter heading
\RedeclareSectionCommand[beforeskip=-1sp plus -1sp minus 1sp]{chapter}

\begin{document}


\chapter{Test}
\chapter{Test with a longer name, test with a longer name, test with a 
 longer name}
\section{test}
\section{test}

\end{document}

两个标题(左侧为单行文本,右侧为双行文本)

如果有两行以上,文本仍然会垂直居中:

四行标题

相关内容