章節標題周圍有緊密的黑框?

章節標題周圍有緊密的黑框?

我希望在章節標題周圍製作一個緊密的黑框,理想情況下1pt每側只有邊距。到目前為止,我最好的結果是soul

使用“靈魂”包

但是,您會注意到底部的邊距過多。此外,反白顯示會在每個奇數頁的頂部重複:

使用“靈魂”包

做這些事情的聰明方法是什麼?我不介意使用 以外的其他東西soul,這似乎是一個很好的解決方案。

MWE如下。請注意,您需要米科達克字體(或可能是任何 TTF 字體?)FONTLOCATION

\documentclass[book,dvipsnames]{memoir}

\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{anyfontsize}
\usepackage{soul}
\sethlcolor{black}

%% Change height of highlight
\makeatletter
 \def\SOUL@hlpreamble{%
 \setul{}{2ex}%
 \let\SOUL@stcolor\SOUL@hlcolor
 \SOUL@stpreamble
 }
\makeatother

\newfontfamily{\archivo}[Path=/FONTLOCATION]{Mikodacs.ttf}

\usepackage{lipsum} %% For dummy text

%% Chapterstyle
\makechapterstyle{lucknerto}{%
\setlength{\beforechapskip}{-2\onelineskip}%
\setlength{\afterchapskip}{2\onelineskip}%
\renewcommand*{\printchaptername}{}%
\renewcommand*{\chapternamenum}{}%
\renewcommand*{\chapnumfont}{\normalfont\large\sffamily\bfseries}%
\renewcommand*{\afterchapternum}{}%
\renewcommand{\printchaptertitle}{\centering\archivo\color{White}\fontsize{23}{27.6}\selectfont\MakeUppercase}
}
\chapterstyle{lucknerto} %% enable

%% Pagestyle 
\makepagestyle{luckner}%
\makeevenhead{luckner}{}{\small{{\MakeUppercase{book title}}}}{} 
\makeoddhead{luckner}{}{\small{{\MakeUppercase{\leftmark}}}}{}
\makeevenfoot{luckner}{\large{\thepage}}{}{}
\makeoddfoot{luckner}{}{}{\large{\thepage}}
\pagestyle{luckner} %% enable

\begin{document}
\chapter{\hl{Foobar}}
\lipsum[1-20]
\end{document}

答案1

樣式非常簡單,tcolorbox並且有一個特殊的\tcbox命令,可以根據個人喜好進行修改。

「困難」在於理解memoir章節標題的意思。我必須改變\printchaptertitle以進行爭論(這是常見的情況),而不是處理動人的爭論。

\documentclass[book,dvipsnames]{memoir}

\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{anyfontsize}
\usepackage{soul}
\usepackage{tcolorbox}
\sethlcolor{black}

%% Change height of highlight
\makeatletter
 \def\SOUL@hlpreamble{%
 \setul{}{2ex}%
 \let\SOUL@stcolor\SOUL@hlcolor
 \SOUL@stpreamble
 }
\makeatother

\newfontfamily{\archivo}[Path=/FONTLOCATION]{Micodacs.ttf}

%\newfontfamily{\archivo}{Liberation Sans}

\usepackage{lipsum} %% For dummy text

\tcbset{chapterhead/.style={%
    fontupper=\archivo\fontsize{23}{27.6}\selectfont,
    left skip=1ex, % for example
    nobeforeafter, %no spacing before and after the box etc
    halign=center, % horizontal align within box, can be omitted
    valign=center, % vertical align within box, can be omitted
    colback=black, % black background colour
    size=tight, % tight box
    colupper=white, % white foreground colour
  }
}

\newtcbox{\blackbox}[1][]{%
  chapterhead,
  #1,
}

%% Chapterstyle
\makechapterstyle{lucknerto}{%
\setlength{\beforechapskip}{-2\onelineskip}%
\setlength{\afterchapskip}{2\onelineskip}%
\renewcommand*{\printchaptername}{}%
\renewcommand*{\chapternamenum}{}%
\renewcommand*{\chapnumfont}{\normalfont\large\sffamily\bfseries}%
\renewcommand*{\afterchapternum}{}%
\renewcommand{\printchaptertitle}{\centering\tcbox[nobeforeafter,halign=center,valign=center,colback=black,size=tight,colupper=white,code={\noexpand\MakeUppercase}]}%\centering\archivo\color{blue}\fontsize{23}{27.6}\selectfont\MakeUppercase}
\renewcommand{\printchaptertitle}[1]{\centering\blackbox{\MakeUppercase{##1}}}%\centering\archivo\color{blue}\fontsize{23}{27.6}\selectfont\MakeUppercase}
}
\chapterstyle{lucknerto} %% enable

%% Pagestyle 
\makepagestyle{luckner}%
\makeevenhead{luckner}{}{\small{{\MakeUppercase{book title}}}}{} 
\makeoddhead{luckner}{}{\small{{\MakeUppercase{\leftmark}}}}{}
\makeevenfoot{luckner}{\large{\thepage}}{}{}
\makeoddfoot{luckner}{}{}{\large{\thepage}}
\pagestyle{luckner} %% enable

\begin{document}
\chapter{Foobar}
\lipsum[1-20]
\end{document}

在此輸入影像描述

使用 Mikodacs 字型輸出:

在此輸入影像描述

相關內容