3

In the chapter heading style from defined in the MWE below, the text of the chapter heading is aligned at the top of the chapter number (See first image). See Schweinebacke's answers to Chapter heading style for more information about the style.

For multi-line-headings this is good, however for a single line heading I would like to center the chapter heading with respect to the chapter number (See second image for the wanted result). So I need a different alignment depending on the number of lines of the chapter heading. The chapter number and the vertical line stay at the same position and the heading is alligned at the center of the number instead of at the top of the chapter number.

Can somebody help?

\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}

enter image description here

enter image description here

  • And if the heading has three or more lines? – Schweinebacke Aug 28 '17 at 13:27
  • I already know all the chapter names, and no chapters have more than three lines. – SLeenders Aug 28 '17 at 13:51
2

I would change the optional argument of \rule to only -.75\dp\strutbox and then also redefine \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}

enter image description here

enter image description here

2

You can redefine \chapterlinesformat to put two (by default) vertically centered \parboxes side by side.

\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}

Two headings (left with single line text, right with two lines)

If you have more than two lines, the text will still be vertically centered:

Four lines heading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.