
섹션에 대한 디자인을 설정하려고 하는데 이 문제를 해결할 수 없습니다. 섹션 번호(숫자만) 주위에 상자를 만들고 바로 옆에 섹션 제목을 넣고 싶습니다. 그렇게 하기는 쉽지만 전체 제목 아래에 있는 줄에도 연결하고 싶습니다. 이미 설정할 수 있었지만 제목이 한 줄인 섹션에만 적용되었습니다. 두 개 이상의 줄이 포함된 섹션이 있으면 상자와 줄의 연결이 끊어집니다. 최적의 솔루션은 상자가 선이 있는 곳까지 자동으로 늘어나 항상 연결되도록 하는 것입니다.
여기 내 MWE가 있습니다. booktabs와 tikz를 포함시켰습니다. 어차피 둘 다 사용할 것이기 때문입니다. 따라서 tikz나 표 형식 설정을 포함한 솔루션은 완벽하게 좋습니다.
\documentclass[parskip=half]{scrreprt}
\usepackage{tikz}
\usepackage{booktabs}
\usepackage{lipsum}
\makeatletter
\renewcommand\sectionlinesformat[4]{\Ifstr{#1}{section}
{\rlap{}\colorbox{darkgray}{\raisebox{0pt}[13pt][3pt]{
\makebox{\selectfont\color{white}{\thesection}}}}\enskip#4\par\nobreak
\kern-1.48\ht\strutbox\textcolor{darkgray}{\rule{\linewidth}{.8pt}}}
{\@hangfrom{\hspace*{#2}#3}{#4}}
}
\makeatother
\begin{document}
\chapter{Some random chapter}
Don't even care for the chapter!
\section{Some short titled section}
\lipsum[1]
\section{Some very long titled section title, which is way too long to fit in one line, so it takes up more lines and destroys my section style}
\lipsum[1]
\end{document}
미리 감사드립니다.
답변1
나는 테이블을 사용하여 하나의 솔루션을 직접 찾았습니다.
\documentclass[parskip=half]{scrreprt}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{lipsum}
\usepackage[table,xcdraw]{xcolor}
\newcommand\btrule[1]{\specialrule{#1}{0pt}{0pt}}
\renewcommand\sectionlinesformat[4]{
\arrayrulecolor{darkgray}\begin{tabularx}{\textwidth}{>{\columncolor{darkgray}}>{\raggedright}l@{}p{0.01cm}Xc}
\textcolor{white}{\thesection} & & #4 \\ \btrule{1.5pt}
\end{tabularx}
}
\begin{document}
\chapter{Some random chapter}
Don't even care for the chapter!
\section{Some short titled section}
\lipsum[1]
\section{Some very long titled section title, which is way too long to fit in one line, so it takes up more lines and destroys my section style}
\lipsum[1]
\end{document}
그것은 내 목적에 부합하므로 해결책이라고 생각합니다.