![如何在 \sectionmark 中使用 adjustmentbox?](https://rvso.com/image/286976/%E5%A6%82%E4%BD%95%E5%9C%A8%20%5Csectionmark%20%E4%B8%AD%E4%BD%BF%E7%94%A8%20adjustmentbox%EF%BC%9F.png)
我想在 \sectionmark 中使用 adjustmentbox,但它不起作用。有解決方法嗎?
\documentclass{book}
\usepackage{blindtext}
\usepackage{adjustbox}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{\markright{#1 \adjustbox{valign=t}{\rule{1.5pt}{\baselineskip}} \thesection}}
\fancyhead[RO]{\rightmark}
\fancyhead[LO]{}
\begin{document}
\chapter{An example chapter}
\section{An example section}
\blindtext[25]
\end{document}
答案1
和\rule
都是脆弱的命令,因此在移動參數(其中的參數是)時\adjustbox
應該在它們前面使用。\protect
\sectionmark
然而,有一個更好的方法來實現你的願望:
\documentclass{book}
\usepackage{blindtext}
\usepackage{fancyhdr}
\pagestyle{fancy}
\renewcommand{\sectionmark}[1]{%
\markright{#1 \strut\vrule width 1.5pt\relax\ \thesection}}
\fancyhead[RO]{\rightmark}
\fancyhead[LO]{}
\begin{document}
\chapter{An example chapter}
\section{An example section}
\blindtext[25]
\end{document}