![我如何才能将相同的格式命令应用于参考书目标题和所有其他章节标题?](https://linux22.com/image/451659/%E6%88%91%E5%A6%82%E4%BD%95%E6%89%8D%E8%83%BD%E5%B0%86%E7%9B%B8%E5%90%8C%E7%9A%84%E6%A0%BC%E5%BC%8F%E5%91%BD%E4%BB%A4%E5%BA%94%E7%94%A8%E4%BA%8E%E5%8F%82%E8%80%83%E4%B9%A6%E7%9B%AE%E6%A0%87%E9%A2%98%E5%92%8C%E6%89%80%E6%9C%89%E5%85%B6%E4%BB%96%E7%AB%A0%E8%8A%82%E6%A0%87%E9%A2%98%EF%BC%9F.png)
我已获得一个模板,该模板将相同的格式命令应用于所有部分。现在我添加了参考书目,并希望其标题采用相同的格式。实现此目的的最简单方法是什么?
\documentclass{scrartcl}
\usepackage{xcolor,biblatex}
\addbibresource{\jobname.bib}
\begin{filecontents}{\jobname.bib}
@article{Test,
author = {Test, A},
title = {What a test}
}
\end{filecontents}
\newcommand{\headingformatting}[1]{\noindent\fcolorbox{black}{orange}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxrule-2\fboxsep\relax}
#1
\end{minipage}}}
\begin{document}
\headingformatting{\section{Test}}
Here I am citing \cite{Test}
\printbibliography
\end{document}
请忽略我的排版不太令人满意的事实\headingformatting
。我只是想从技术角度展示文档的样子。
答案1
正如评论中提到的那样,对此的最佳解决方案是使用 KOMA-Script 功能来确保\section
按需要排版,而无需手动\headingformatting
调用每个功能\section
。
因为我不知道该怎么做,所以这里提供了一种解决方法,即定义一个也适用于的biblatex
新标题样式。\headingformatting
\section
\documentclass{scrartcl}
\usepackage{xcolor,biblatex}
\defbibheading{myheading}[\refname]{\headingformatting{\section{#1}}}
\newcommand{\headingformatting}[1]{\noindent\fcolorbox{black}{orange}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxrule-2\fboxsep\relax}
#1
\end{minipage}}}
\addbibresource{biblatex-examples.bib}
\begin{document}
\headingformatting{\section{Test}}
Here I am citing \cite{sigfridsson}
\printbibliography[heading=myheading]
\end{document}
此处显示的定义基于\section
。如果您想要无编号样式,可以选择类似
\makeatletter
\defbibheading{myheading}[\refname]{%
\headingformatting{\section*{#1}}%
\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
\makeatother
或者
\makeatletter
\defbibheading{myheading}[\refname]{%
\headingformatting{\section*{#1}}%
\addcontentsline{toc}{section}{#1}%
\@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
\makeatother
答案2
这应该可行。
\documentclass{scrartcl}
\usepackage{xcolor,biblatex}
\addbibresource{\jobname.bib}
\begin{filecontents}{\jobname.bib}
@article{Test,
author = {Test, A},
title = {What a test}
}
\end{filecontents}
\newcommand{\headingformatting}[1]{\noindent\fcolorbox{black}{orange}{%
\begin{minipage}{\dimexpr\textwidth-2\fboxrule-2\fboxsep\relax}
#1
\end{minipage}}}
\begin{document}
\headingformatting{\section{Test}}
Here I am citing \cite{Test}
\printbibliography[title=\headingformatting{\refname}]
\end{document}