3

I am working in an {article}-class document with BibLaTeX used.

EDIT 240526: I am working in Overleaf.

I am failing to apply an automatic recalculation of my \biblabelsep. A screenshot of what I have but want to modify follows.

enter image description here

In the image, the red solid vertical line is the desired indent.

Unfortunately, the \biblabelsep, marked by the blue dashed horizontal line (at entry #9) is held fixed and so does not auto-adjust. Currently, as I see, a given bibliography entry is aligned to a position that is a sum of the label's length plus \biblabelsep, which, in addition to producing a seemingly overlarge indent, pushes entries whose labels are longer even farther back, as seen with entry #10.

Q: how can I achieve a desired indent auto-adjusting to the label's width instead of being fixed and summative? All the labels are left-aligned and this setting I want to retain.

EDIT 240526: Please read 'desired alignment with \biblabelsep auto-adjusting'.

Below is the code that replicates the document:

\documentclass[12pt,a4paper]{article}

%CONTROL SEPARATION BETWEEN SECTION LABEL AND SECTION NAME
\makeatletter
\renewcommand*{\@seccntformat}[1]{\hbox to 1.5cm{\csname the#1\endcsname}}
\makeatother

\usepackage{parskip}
\usepackage[locallabelwidth=true]{biblatex}
%FORMAT THE BIBLIOGRAPHY
\setlength{\biblabelsep}{1.5cm}
%ADD .bib FILES
\addbibresource{biblatex-examples.bib}

\begin{document}

\section{Section}\subsection{Subsection}

Example $\#1$ of a citation \cite{bertram}. 
Example $\#2$ of a citation \cite{doody}. 
Example $\#3$ of a citation \cite{gillies}. 
Example $\#4$ of a citation \cite{glashow}. 
Example $\#5$ of a citation \cite{herrmann}. 
Example $\#6$ of a citation \cite{kastenholz}. 
Example $\#7$ of a citation \cite{murray}. 
Example $\#8$ of a citation \cite{reese}. 
Example $\#9$ of a citation \cite{shore}. 
Example $\#10$ of a citation \cite{spiegelberg}. 

\AtNextBibliography{\small}\printbibliography[heading=subbibnumbered]

\end{document}
7
  • 1
    Welcome to TeX.SE!
    – Mensch
    Commented May 25 at 20:23
  • I don't get that output from your code. My numbers are not left aligned as your are.
    – cfr
    Commented May 25 at 23:56
  • 1
    Unless you have several bibliographies, it is in general vastly preferable to change \bibfont rather than to use \AtNextBibliography for font size changes as explained in tex.stackexchange.com/a/609374/35864 (though, to be fair, in this specific case the downsides of this approach might not be relevant because we force the label distance anyway).
    – moewe
    Commented May 26 at 6:17
  • The MWE does not appear to reproduce the result in the screenshot for me. You may want to adjust one or the other to make the question more consistent.
    – moewe
    Commented May 26 at 6:31
  • 1
    This may just be me being thick, but as far as I understand, what you want to achieve is a situation in which all labels are left-aligned at the margin, but the item text starts aligned at 1.5cm from the left margin (in line with the headings etc.). For me this would be the opposite of auto indent, since this indentation would be chosen independent of the label widths (in particular this large indent is used when a smaller indent would visually suffice because the labels are shorter). Can you clarify what you want in more detail?
    – moewe
    Commented May 26 at 6:35

3 Answers 3

4

A bit hackish (I am sure there is far better methods) but how about this?

\documentclass[12pt,a4paper]{article}

%CONTROL SEPARATION BETWEEN SECTION LABEL AND SECTION NAME
\makeatletter
\renewcommand*{\@seccntformat}[1]{\hbox to 1.5cm{\csname the#1\endcsname}}
\makeatother

\usepackage{parskip}
\usepackage[locallabelwidth=true]{biblatex}
\setlength{\biblabelsep}{1.5cm}

\defbibenvironment{bibliography}
{\list
    {%
        \parbox{0pt}{%
        \printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}%
        }%
    }{%
        \setlength{\labelwidth}{0pt}%
        \setlength{\leftmargin}{1.5cm}%
        \setlength{\labelsep}{\dimexpr\leftmargin-\labelwidth}%
        \setlength{\itemsep}{\bibitemsep}%
        \setlength{\parsep}{\bibparsep}}%
    }
{\endlist}
{\item}


\addbibresource{biblatex-examples.bib}

\begin{document}
    
    \section{Section}\subsection{Subsection}
    
    Example $\#1$ of a citation \cite{bertram}. 
    Example $\#2$ of a citation \cite{doody}. 
    Example $\#3$ of a citation \cite{gillies}. 
    Example $\#4$ of a citation \cite{glashow}. 
    Example $\#5$ of a citation \cite{herrmann}. 
    Example $\#6$ of a citation \cite{kastenholz}. 
    Example $\#7$ of a citation \cite{murray}. 
    Example $\#8$ of a citation \cite{reese}. 
    Example $\#9$ of a citation \cite{shore}. 
    Example $\#10$ of a citation \cite{spiegelberg}. 
    
    \AtNextBibliography{\small}\printbibliography[heading=subbibnumbered]
    
\end{document}

img

3

Biblatex provides a hook for code which should be executed at the beginning of the bibliography environment. This hook can be used to change the definition of the item label. I modified the example given for defining a shorthands bibliography environment in the manual, adapting it for the hook since we don't really need to rewrite everything.

Although your code did not left-align the numbers for me when I compiled it, this does.

The definition of \biblabelsep is a semi-guess as to what Biblatex is doing and what LaTeX is doing. I briefly tried to figure out the width of the indentation for section titles, but gave up. If you want to be certain it is spot on, you could figure that out or simply define the sectioning so that you know the dimensions involved (e.g. sectsty or whatever).

Anyway, I used 2em less the label width, because Biblatex uses twice the paragraph indent by default, except that it sets the indentation to 1em if it is zero. Since you're using parskip, this gets us 2em. This turns out to look about right when compared with the section indentation. However, I'm not at all convinced by this calculation, personally. It seems rather implausible.

\documentclass[12pt,a4paper]{article}

\makeatletter
\renewcommand*{\@seccntformat}[1]{\hbox to 1.5cm{\csname the#1\endcsname}}
\makeatother
\usepackage{calc}
\usepackage{parskip}
\usepackage[locallabelwidth=true]{biblatex}
\addbibresource{biblatex-examples.bib}
\setlength{\biblabelsep}{2em-\labelnumberwidth}
 
\AtBeginBibliography{%
  \renewcommand*{\makelabel}[1]{#1\hss}% based on shorthands eg in manual
}

\begin{document}

\section{Section}\subsection{Subsection}

Example $\#1$ of a citation \cite{bertram}. 
Example $\#2$ of a citation \cite{doody}. 
Example $\#3$ of a citation \cite{gillies}. 
Example $\#4$ of a citation \cite{glashow}. 
Example $\#5$ of a citation \cite{herrmann}. 
Example $\#6$ of a citation \cite{kastenholz}. 
Example $\#7$ of a citation \cite{murray}. 
Example $\#8$ of a citation \cite{reese}. 
Example $\#9$ of a citation \cite{shore}. 
Example $\#10$ of a citation \cite{spiegelberg}. 

\AtNextBibliography{\small}\printbibliography[heading=subbibnumbered]

\end{document}

aligned labels and entries

3

You can force a fixed indent without regards for label widths by redefining the bibliography environment. Its default for numeric styles can be found in numeric.bbx (ll. 24-37 in v3.20). In order to understand the parameters, you may want to have a look at How can I modify the settings of the margin item in a list? (with an image taken from the layouts or enumitem documentation).

Essentially we fix \leftmargin to the desired indent value. Then it's probably best to set some non-zero \labelsep (we just take \biblabelsep, the default). The label width can then be calculated as the available space in \leftmargin minus \labelsep.

We redefine \makelabel compared to the standard definition in order to obtain left-aligned labels.

You will run into trouble if your label is longer than the width we reserve for it, but the result here will still look OK-ish.

\documentclass[12pt,a4paper]{article}

\makeatletter
\renewcommand*{\@seccntformat}[1]{\hbox to 1.5cm{\csname the#1\endcsname}}
\makeatother

\usepackage{parskip}
\usepackage{biblatex}

\renewcommand*{\bibfont}{\normalfont\small}

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\setlength{\leftmargin}{1.5cm}%
      \setlength{\labelsep}{\biblabelsep}%
      \setlength{\labelwidth}{\dimexpr1.5cm-\labelsep\relax}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{##1\hss}}
  {\endlist}
  {\item}

\addbibresource{biblatex-examples.bib}

\begin{document}

\section{Section}\subsection{Subsection}

Example $\#1$ of a citation \cite{bertram}. 
Example $\#2$ of a citation \cite{doody}. 
Example $\#3$ of a citation \cite{gillies}. 
Example $\#4$ of a citation \cite{glashow}. 
Example $\#5$ of a citation \cite{herrmann}. 
Example $\#6$ of a citation \cite{kastenholz}. 
Example $\#7$ of a citation \cite{murray}. 
Example $\#8$ of a citation \cite{reese}. 
Example $\#9$ of a citation \cite{shore}. 
Example $\#10$ of a citation \cite{spiegelberg}. 

\printbibliography[heading=subbibnumbered]

\end{document}

Left-aligned labels with 1.5cm indent.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .