0

I have been given a template that applies the same formatting command to all sections. I now added a bibliography and want the title of it to be formatted the same way. What is the simplest way to achieve this?

\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}

Please ignore the fact, that my \headingformatting is typographically not appeasing. I just wanted to show how the document looks from a technical point of view.

2
  • I'm not sure about the use case of your template, but surely in the example the best solution to this would be to use KOMA-Script features to make sure that \section is typeset as desired without having to invoke \headingformatting for each \section manually.
    – moewe
    Jun 23 at 15:04
  • @moewe I agree and would change that in the future, but as of now I quickly had to add a bibliography to an existing file, so I didn‘t want to break anything by fiddling around.
    – TobiBS
    Jun 25 at 8:30

2 Answers 2

2

As mentioned in the comments the best solution to this would be to use KOMA-Script features to make sure that \section is typeset as desired without having to invoke \headingformatting for each \section manually.

Since I don't know how to do that, here is the biblatex workaround that defines a new heading style that also applies \headingformatting for \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}

References header highlighted in the same way as "Test"

The definition shown here is based on \section. If you want an unnumbered style, you can go for something like

\makeatletter
\defbibheading{myheading}[\refname]{%
  \headingformatting{\section*{#1}}%
  \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
\makeatother

or

\makeatletter
\defbibheading{myheading}[\refname]{%
  \headingformatting{\section*{#1}}%
  \addcontentsline{toc}{section}{#1}%
  \@mkboth{\abx@MakeMarkcase{#1}}{\abx@MakeMarkcase{#1}}}
\makeatother
1

This should works.

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.