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}