如何将 Nils L 的“假粗体”用于章节、小节、小小节和段落标题?

如何将 Nils L 的“假粗体”用于章节、小节、小小节和段落标题?

我想(全局)将所有部分(小节、小节和段落)标题设置\medbold

\newcommand{\medbold}[1]{%
\pdfliteral direct {2 Tr 0.3 w} 
\pdfliteral direct {0 Tr 0 w}%
}

(以上代码全部归功于用户尼尔斯·L和他们的回答对此StackExchange 问题

例如,我希望节标题看起来像

\medbold{[SectionNumber]} [Default Spacing] \medbold{SectionTitle}

我该怎么做?提前谢谢您。最低工作示例如下

最小工作示例

% Made on Overleaf with the pdfLaTeX compiler
\documentclass{article}
\usepackage{lipsum} % for dummy text
\usepackage{hyperref} % to give proper credit for the \medbold code
\usepackage{mathtools} %for \mathclap

%Definition of "\medbold"
%Full credit to this code goes to StackExchange Nils L (see href below for more details)
\newcommand{\medbold}[1]{%
    \pdfliteral direct {2 Tr 0.3 w} %the second factor is the boldness
      #1%
    \pdfliteral direct {0 Tr 0 w}%
}

\usepackage[default,
            semibold]{sourceserifpro} %I like this font :)


\title{Medbold Section StackExchange MWE}
\author{cluelessmathematician}
\date{February 2023}

\begin{document}

\maketitle

\section{My Question}

I would like to (globally) set all section (subsection, subsubsection, and paragraph) headers be $\setminus$\texttt{medbold} as defined by

\begin{verbatim}
            \newcommand{\medbold}[1]{%
            \pdfliteral direct {2 Tr 0.3 w} 
            \pdfliteral direct {0 Tr 0 w}%
             }
\end{verbatim}
(Full credit for above code goes to user \href{https://tex.stackexchange.com/users/7993/nils-l}{Nils L} with their \href{https://tex.stackexchange.com/a/102706/268642}{answer} to this \href{https://tex.stackexchange.com/q/102578/268642}{StackExchange question}.)\\


\noindent For example, I would like the above section header to look like
\begin{center}
    \medbold{1} \ \ \medbold{My Question}
\end{center}
\noindent How do I do this? Thank you very much in advance.

\subsection{Dummy Subsection}
\lipsum[1]
\subsubsection{Dummy Subsubsection}
\lipsum[2]
\paragraph{Dummy Paragraph}
\lipsum[3]

\end{document}

答案1

答案是,在或Nils L中都可以工作,希望您期望在 中工作,如果是,则以下将起作用:XeLaTeXLuaLaTeXPDFLaTeXMWE

\documentclass{book}
\usepackage{titlesec}
\usepackage[bold=0.35]{xfakebold}
\begin{document}

\titleformat*{\section}{\setBold}

\section{A Head Test}
\unsetBold

This is for test

\end{document}

另外,请注意,这可能适用于所有TeX引擎

在此处输入图片描述

\unsetBold稍后我将检查是否可以自动修复。

相关内容