![正文外面带有图形页码的页眉](https://linux22.com/image/386875/%E6%AD%A3%E6%96%87%E5%A4%96%E9%9D%A2%E5%B8%A6%E6%9C%89%E5%9B%BE%E5%BD%A2%E9%A1%B5%E7%A0%81%E7%9A%84%E9%A1%B5%E7%9C%89.png)
我正在使用 LuaLaTex 格式化一本书。我需要获取如下标题
和
我正在使用 titlesec 包。因此我需要页码超出标准 \textwidth。到目前为止,我能做的最好的事情是
\documentclass[10pt]{book}
\usepackage{fontspec}
%\setmainfont[Ligatures=TeX]{Apollo MT}
\usepackage[svgnames]{xcolor}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}% environment for colored and framed text boxes with a heading line
\usepackage[vcentering, hcentering, inner=10.5mm,outer=10.5mm,top=25.5mm, bottom=25.5mm,showframe]{geometry} % Extended page layout customization
\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages
%Page headers
%colored box for page numbers
\newtcbox{\mypagenum}{enhanced,nobeforeafter,tcbox raise base,boxrule=1pt,top=0mm,bottom=0mm,
colframe=red,coltext=black,colback=white, halign = right,
width=2.55cm,arc=3.5mm, sharp corners=west, boxsep=2mm,
}
\newpagestyle{main}{
\sethead[][][\thesection~\sectiontitle~\mypagenum\thepage] % even
{\mypagenum\thepage Chapter \thechapter\chaptertitle}{}{} % odd
}
\pagestyle{main}
\begin{document}
\chapter{My title}
\lipsum[20-30]
\section{My Section}
\lipsum[20-30]
\end{document}
我找不到一种(简单的)方法来扩展页眉宽度或定位页码,例如使用 \hspace{-XXcm}。
答案1
解决方案是\widenhead*
来自的命令titleps
和两个对称的 \tcbox
es:
\documentclass[10pt]{book}
\usepackage{fontspec}
%\setmainfont[Ligatures=TeX]{Apollo MT}
\usepackage[svgnames]{xcolor}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage[many]{tcolorbox}% environment for colored and framed text boxes with a heading line
\usepackage[vcentering, hcentering, inner=10.5mm,outer=10.5mm,top=25.5mm, bottom=25.5mm,showframe]{geometry} % Extended page layout customization
\geometry{papersize={189mm,246mm}} % Possible dimensions of textbook pages
%Page headers
%colored box for page numbers
\newtcbox{\mypagenum}{enhanced, nobeforeafter, tcbox raise base, boxrule=1pt, top=0mm, bottom=0mm,
colframe=red, coltext=black, colback=white, halign = right,
width=2.55cm, arc=3.5mm, sharp corners=west, boxsep=2mm,
}
\newtcbox{\mypagenumb}{enhanced, nobeforeafter, tcbox raise base, boxrule=1pt, top=0mm, bottom=0mm,
colframe=red, coltext=black, colback=white, halign=right,
width=2.55cm, arc=3.5mm, sharp corners=east, boxsep=2mm,
}
\newpagestyle{main}{%
\widenhead*{0cm}{\dimexpr 1cm+1.5pt}
\sethead[\mypagenum\thepage~Chapter\,\thechapter\enspace\chaptertitle][][] % even
{}{}{\thesection~\sectiontitle~\mypagenumb\thepage} % odd
}
\pagestyle{main}
\begin{document}
\chapter{My title}
\lipsum[20-30]
\section{My Section}
\lipsum[20-30]
\end{document}