我尝试使用 hbox/wbox、tabular 和 colorboxes。
只需查看图像和此来源。
有人能帮忙设计正确的造型吗?
\documentclass{book}
\usepackage{lipsum}
\usepackage{tcolorbox}
\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
\reset@font
\parindent \z@
\vspace*{10\p@}%
\begin{tabular}{l l}
\begin{tcolorbox}[center title,left=5pt,right=0pt,top=5pt,bottom=5pt,width=5cm, colback=red, colframe=red,enlarge left by=0mm,boxsep=5pt,arc=0pt,outer arc=0pt,]
\fontsize{14pt}{14pt}\selectfont \textcolor{white}{\@chapapp{} \thechapter }
\end{tcolorbox}
&
\begin{tcolorbox}[center title,left=0pt,right=0pt,top=5pt,bottom=5pt,colback=black, colframe=black,enlarge left by=0mm,boxsep=5pt,arc=0pt,outer arc=0pt,]
\fontsize{14pt}{14pt}\selectfont \textcolor{white}{#1}
\end{tcolorbox}
\end{tabular}
}
\begin{document}
\chapter{Introduction}
\lipsum
\chapter{Some very long title with many words and terms}
\lipsum
\end{document}
答案1
raster
您可以使用带有右框的表格来代替表格extruded
。以下代码需要进行一些几何调整,但可以作为起点。
\documentclass{book}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
\reset@font
\parindent \z@
\vspace*{10\p@}%
\begin{tcbraster}[raster columns=2, sharp corners, raster equal height, notitle, sharp corners, colupper=white, fontupper=\fontsize{14pt}{14pt}\selectfont, raster width=\linewidth+\marginparwidth+\marginparsep, raster force size=false]
\begin{tcolorbox}[halign=center, valign=center, colback=red, colframe=red, add to width=-4cm]
\@chapapp{} \thechapter
\end{tcolorbox}
\begin{tcolorbox}[colback=black, colframe=black, extrude right by=\marginparwidth+\marginparsep]
#1
\end{tcolorbox}
\end{tcbraster}
}
\begin{document}
\chapter{Introduction}
\lipsum
\chapter{Some very long title with many words and terms}
\lipsum
\end{document}
答案2
下面给出的 MWE 将为您设置:
\documentclass{book}
\usepackage{lipsum}
\usepackage{tcolorbox,array}
\makeatletter
\def\thickhrulefill{\leavevmode \leaders \hrule height 1ex \hfill \kern \z@}
\def\@makechapterhead#1{%
\reset@font
\parindent \z@
\vspace*{10\p@}%
\def\xwidth{5cm}%
\def\xsep{1pc}%
\global\setbox0=\vbox{\begin{tcolorbox}[center title,left=0pt,right=0pt,top=5pt,bottom=5pt,colback=black, colframe=black,enlarge left by=0mm,boxsep=5pt,arc=0pt,outer arc=0pt,width=\textwidth+\xwidth]
\parbox{\dimexpr(\textwidth-\xwidth-\xsep-\xwidth)}{\raggedright\fontsize{14pt}{18pt}\selectfont \color{white}#1}%
\end{tcolorbox}}
\begin{tabular}{@{}m{\xwidth}@{\hspace{\xsep}}m{\dimexpr(\textwidth-\xwidth-\xsep)}@{}}
\begin{tcolorbox}[center title,left=5pt,right=0pt,top=5pt,bottom=5pt,, colback=red, colframe=red,enlarge left by=0mm,boxsep=5pt,arc=0pt,outer arc=0pt,width=\xwidth,height=\the\ht0-2.1mm]
\fontsize{14pt}{18pt}\selectfont \textcolor{white}{\@chapapp{} \thechapter }
\end{tcolorbox}
&
\box0
\end{tabular}
}
\begin{document}
\chapter{Introduction}
\lipsum[1]
\chapter{Some very long title with many words and terms}
\lipsum[1]
\chapter{Some very long title with many words and terms Some very long title with many words and terms}
\lipsum[1]
\end{document}
请注意,有两个命令\xwidth
,\xsep
分别设置红框的宽度和红框与黑框之间的间隔。您可以更改它。