从接受的答案开始
我做了以下操作来获取 scrbook 中的自定义章节标题(最小(非)工作示例):
\documentclass[]{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{xcolor}
\newlength{\sectsquaresize}
\setlength\sectsquaresize{70pt}
\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont}
\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\color{black}}
\renewcommand\sectionformat{%
\parbox{\sectsquaresize}{%
\setlength\fboxsep{0pt}%
\setlength\fboxrule{1pt}%
\fbox{\colorbox{yellow}{%
\parbox[m][\dimexpr \sectsquaresize - 2 \fboxrule][c]{\dimexpr \sectsquaresize - 2 \fboxrule}%
{\centering{\usekomafont{sectionnumber}{\thesection\autodot}}}}}}%
\quad%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}}%
}{}%
}
\makeatother
\newcommand{\sectionproc}[1]{\parbox[m][\sectsquaresize][c]{\dimexpr\textwidth - \sectsquaresize - 17pt}{\raggedright #1}}
\newcommand{\ltdis}[1]{#1}
\setlength{\parindent}{0pt}
\begin{document}
\chapter{Erkrankungen des Bewegungsapparats}
\section[Rheumatoide Arthritis]{\sectionproc{Rheumatoide Arthritis\newline\ltdis{Arthritis rheumatoides}}}
\blindtext
\section[Rheumatismus]{\sectionproc{Rheumatismus\newline\ltdis{Rheumatismus}}}
\blindtext
\section[Arthrose mit besonderer Deformation der Gelenke]{\sectionproc{Arthrose mit besonderer Deformation der Gelenke\newline\ltdis{Arthrosis deformans, spondylosis deformans}}}
\blindtext
\section[Händezittern]{\sectionproc{Händezittern\newline\ltdis{Tendovaginitis}}}
\blindtext
\end{document}
在输出中,水平线\rule
(在带框的黄色方块之后水平开始并在文本行末端结束)在垂直方向上未与黄色方块的下方黑色框线对齐(正如我希望的那样)。
我尝试引入之\vspace*{[a negative value]}
后来\par\nobreak
解决这个问题,但找不到适用于所有情况的合适表达方式。
\renewcommand\sectionlinesformat[4]{%
\@hangfrom{\hspace*{#2}#3}{#4}%
\ifstr{#1}{section}{%
\par\nobreak%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}}{%
\hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}}%
}{}%
}
我该怎么做才能使 \rule 与黄色正方形的下方黑框线对齐?
答案1
也许下面的操作可以满足您的要求:
\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[german]{babel}
\usepackage{etoolbox}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{lmodern}% scalable font
\newlength{\sectsquaresize}
\setlength\sectsquaresize{70pt}
\addtokomafont{section}{\fontsize{14pt}{17pt}\selectfont}%<- changed
\newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\color{black}}%<- changed
\renewcommand\sectionformat{%
\setlength\fboxsep{0pt}%
\setlength\fboxrule{1pt}%
\fcolorbox{black}{yellow}{%
\parbox[m][\dimexpr \sectsquaresize - 2 \fboxrule][c]{\dimexpr \sectsquaresize - 2 \fboxrule}%
{\centering{\usekomafont{sectionnumber}{\thesection\autodot}}}}%
\quad%
}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
\ifstr{#1}{section}{%
\raisebox{\dimexpr\depth+\dp\strutbox\relax}{%
\makebox[0pt][l]{\@hangfrom{\hspace*{#2}#3}{%
\parbox[m][\sectsquaresize][c]{\dimexpr\textwidth - \sectsquaresize - 17pt}{\raggedsection #4}%
}}%
}%
\ifstr{#3}{}{%
\rule[\dp\strutbox]{\textwidth}{1pt}%
}{%
\hspace*{\sectsquaresize}\rule[\dp\strutbox]{\dimexpr\textwidth-\sectsquaresize}{1pt}%
}%
}{%
\@hangfrom{\hspace*{#2}#3}{#4}% original definition for other section levels
}
}
\makeatother
\newcommand{\ltdis}[1]{#1}
\setlength{\parindent}{0pt}
\begin{document}
\chapter{Erkrankungen des Bewegungsapparats}
\section[Rheumatoide Arthritis]{Rheumatoide Arthritis\newline\ltdis{Arthritis rheumatoides}}
\blindtext
\section[Rheumatismus]{Rheumatismus\newline\ltdis{Rheumatismus}}
\blindtext
\section[Arthrose mit besonderer Deformation der Gelenke]{Arthrose mit besonderer Deformation der Gelenke\newline\ltdis{Arthrosis deformans, spondylosis deformans}}
\blindtext
\section[Händezittern]{Händezittern\newline\ltdis{Tendovaginitis}}
\blindtext
\end{document}
结果: