5

Context: Since my bibliography is constituted of 200+ entries, I want to add margin-notes at each new letter to split the bibliography alphabetically. (I.e., print a "B" in the margin next to the first entry whose author's name starts with B, etc.)
My document uses a KOMA-script class and I use biblatex.

For this, I almost successfully adapted Ulrike Fischer's solution proposed for How to split the bibliography alphabetically?.

Problem: I use KOMA-script's \marginline{<text>} to print text in the margin. However, using this command at the beginning of a paragraph creates a margin-note... that is vertically aligned with the last line of previous paragraph. I thus need to use a \raisebox{-\baselineskip}{<text>} to properly align the marginnote, as shown below.

enter image description here

However, when I do the same in the bibliography, the margin-note is too much "de-raised":

enter image description here

Question: What is the right length to use for lowering the margin note? (and why is it different from \baselineskip?)


Bonus question: The current margin note is a letter with the same font size as the bibliography. I might want to increase its size. The question would be then: How to vertically align the top of the margin note with the top of the relevant bibliographical entry? enter image description here


MWEB

\documentclass[twoside]{scrbook}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage[%
        backend=biber,  %use biber as processing program
        bibstyle=authoryear, %how is LoR organized
        sorting=nyt,    %how are entries sorted in the LoR
    ]{biblatex}
    \addbibresource{\jobname.bib}
    \usepackage{filecontents}

%% Adaptation of Ulrike Fischer's solution https://tex.stackexchange.com/a/150176/64454
\makeatletter
    \bibinitsep=1sp %to trigger blx@initsep
    \def\blx@initsep{%
        \blx@imc@iffieldundef{sortinit}
        {}
        {%
            \ifnum\c@instcount>\@ne
            \blx@imc@iffieldequals{sortinit}\blx@previnit
            {}
            {\marginline{\raisebox{-\baselineskip}{\sffamily\bfseries\printfield{sortinit}}}}
            \fi
            \global\let\blx@previnit\abx@field@sortinit%
        }%
    }
\makeatother
%% End of solution

    \begin{filecontents}{\jobname.bib}
        @InBook{Azerty,
          author =   {Paul Azerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
         Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          year =     2010}


        @Book{Aqsdfgh,
          author =   {Paul Aqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Awxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Awxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          Volume                   = {17},
        }
        @InBook{Bzerty,
          author =   {Paul Bzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}


        @Book{Bqsdfgh,
          author =   {Paul Bqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          year =     2010}

        @Article{Bwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Bwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
        @InBook{Dzerty,
          author =   {Paul Dzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}


        @Book{Dqsdfgh,
          author =   {Paul Dqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Dwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Dwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
        @InBook{Kzerty,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}


        @Book{Zqsdfgh,
          author =   {Paul Dqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Zwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Zwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
    \end{filecontents}

    \usepackage[francais]{babel}
    \usepackage{lipsum}

\begin{document}
    \lipsum[1]

    \marginline{Too high}
    \lipsum[2]


    \marginline{\raisebox{-\baselineskip}{Good}}
    \lipsum[3]

\newpage
    \nocite*
    \printbibliography
\end{document}
  • This seems to have to do with descenders in the previous line. I modified your example to not have letters with descenders in the bib entries, and things looked a bit nicer. – moewe May 28 '17 at 7:39
  • @moewe you mean removing letters like p, q, y, j, etc. ? (So basically, the bottom of the margin note would be aligned with the bottom of the entry's first line -- instead of being "baseline-aligned") – ebosi May 28 '17 at 18:55
3

Don't lower the entry in \marginline but add \leavevmode in front of it to make sure the paragraph started when the command starts doing its work:

\makeatletter
\bibinitsep=1sp %to trigger blx@initsep
\def\blx@initsep{%
  \blx@imc@iffieldundef{sortinit}
    {}
    {%
      \ifnum\c@instcount>\@ne
      \blx@imc@iffieldequals{sortinit}\blx@previnit
        {}
        {\leavevmode\marginline{\sffamily\bfseries\printfield{sortinit}}}%
      \fi
      \global\let\blx@previnit\abx@field@sortinit
  }%
}
\makeatother

and

\lipsum[1]

\leavevmode\marginline{Too high}
\lipsum[2]

\leavevmode\marginline{Good}
\lipsum[3]

enter image description here

enter image description here

1

Iterating on clemens' answer, here is a solution for the "bonus question". Instead of baseline-aligning the bibliographical entry and the margin note (i.e., what is done in clemens' answer), the top of the margin note is now aligned with the top of the bibliographical entry. (More precisely, capital letters of the bibliographical entry are top-aligned with capital letters of the margin note.)

This notably enables to use initials with bigger (or smaller) font size than bibliographical entries' one.

enter image description here

The "trick" is to use a raisebox that drops the initial down so that it is top-aligned with the bibliographical entry's baseline, and then that lowers it up to the height of a bibliographical entry's capital letter.
(The only "problem" that can occur is when the initial is bigger than the entry that is at the bottom of the page – see "L" in the MWE – but in my opinion it is still acceptable)


\documentclass[twoside, a5, 12pt]{scrbook}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage[%
        backend=biber,  %use biber as processing program
        bibstyle=authoryear, %how is LoR organized
        sorting=nyt,    %how are entries sorted in the LoR
    ]{biblatex}
    \addbibresource{\jobname.bib}
    \usepackage{filecontents}


%% Define font for bibliography and marginnote + some length calculation
    \usepackage{calc}
    \newcommand{\mybibliographyfont}{\normalfont}
    \newcommand{\mybibliographymagrinnotefont}{\Huge\sffamily\bfseries}

    \newlength{\normallineheight}
        \setlength{\normallineheight}{\heightof{\mybibliographyfont M}}
    \newlength{\marginnoteheight}
        \setlength{\marginnoteheight}{\heightof{\mybibliographymagrinnotefont M}}

    %% Adaptation of Ulrike Fischer's solution https://tex.stackexchange.com/a/150176/64454
    \makeatletter
        \bibinitsep=1sp %to trigger blx@initsep
        \def\blx@initsep{%
            \blx@imc@iffieldundef{sortinit}
            {}
            {%
                \ifnum\c@instcount>\@ne
                \blx@imc@iffieldequals{sortinit}\blx@previnit
                {}
                {\leavevmode\marginline{\raisebox{\dimexpr\normallineheight-\marginnoteheight\relax}{\mybibliographymagrinnotefont\printfield{sortinit}}}}% The objective is here to top-align capital letters of bib entry and the margin note
                \fi
                \global\let\blx@previnit\abx@field@sortinit%
            }%
        }
    \makeatother
%% End of solution

    \begin{filecontents}{\jobname.bib}
        @InBook{Azerty,
          author =   {Paul Azerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
         Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          year =     2010}


        @Book{Aqsdfgh,
          author =   {Paul Aqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Awxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Awxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          Volume                   = {17},
        }
        @InBook{Bzerty,
          author =   {Paul Bzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}


        @Book{Bqsdfgh,
          author =   {Paul Bqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          year =     2010}

        @Article{Bwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Bwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
        @InBook{Dzerty,
          author =   {Paul Dzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}


        @Book{Dqsdfgh,
          author =   {Paul Dqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Dwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Dwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
        @InBook{Kzerty,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}
        @InBook{Kzerty2,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}
        @InBook{Kzerty3,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}   
        @InBook{Kzerty4,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}    
        @InBook{Kzerty5,
          author =   {Paul Kzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
          year =     2010}                         
        @InBook{Lzerty,
          author =   {Paul Lzerty and Doe, John and Musterman, Erika},
          title =    {Lorem ipsum dolor sit amet, consectetur adipiscing elit.},
          chapter =      {Cras bibendum leo mauris, a ornare dolor rutrum egestas.},
          publisher =    {Donec consequat},
         Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          year =     2010}
        @Book{Lqsdfgh,
          author =   {Paul Lqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          year =     2010}

        @Article{Lwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Lwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Url                      = {http://dx.doi.org/10.007/1234567890987654321},
          Volume                   = {17},
        }
        @Book{Zqsdfgh,
          author =   {Paul Dqsdfgh and Musterman, John and Doe, Erika},
          title =    {Mauris bibendum diam lorem},
          publisher =    {Aliquam},
          year =     2010}

        @Article{Zwxcvb,
          Title                    = {In euismod est eget urna euismod, cursus tincidunt odio dignissim.},
          Author                   = {Paul Zwxcvb and Musterdoe, Jerika and Dann, Eron},
          Journal                  = {Maecenas pharetra},
          Year                     = {2010},
          Number                   = {13},
          Pages                    = {13--17},
          Publisher                = {Pellentesque},
          Volume                   = {17},
        }
    \end{filecontents}

    \usepackage[francais]{babel}
    \usepackage{lipsum}

\begin{document}
    \nocite*
    \mybibliographyfont
    \printbibliography
\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.