I would like to color year and author with biblatex. When using natbib for citing, authors and year were blue, but after changing to biblatex only year is dyed in the desired color.
Is there a way to make only Author(s) and year blue when cited in text, while (), page references and cf. remain black? I would like this to appear in the printed version as well. It might be a problem of translation, but I found nothing that has addressed this issue before.
Thank you very much ahead!
\documentclass[%
ngerman,english,%
toc=chapterentrywithdots, % Macht, dass auch bei den Chaptern Punkte im Inhaltsverzeichnis sind
BCOR=6mm,cdgeometry=no,%
DIV=13,cdfont=true,
listof=totoc
]{tudscrreprt}
\usepackage{filecontents}
\begin{filecontents}{shortbib.bib}
@article{greenwade93,
author = "George D. Greenwade",
title = "The {C}omprehensive {T}ex {A}rchive {N}etwork ({CTAN})",
year = "1993",
journal = "TUGBoat",
volume = "14",
number = "3",
pages = "342--351"
}
@article{petritan2010,
title = {Influence of different cutting types on growth of planted beech and Douglas fir saplings},
volume = {81},
issn = {0300-4112},
url = {http://doi.org/10.4432/0300-4112-81-40},
doi = {10.4432/0300-4112-81-40},
pages = {40--52},
number = {2},
journaltitle = {Forstarchiv},
author = {Petriţan, Ion Catalin and Lüpke, Burghard von and Petriţan, Any Mary},
date = {2010}
}
@article{stancioiu2006,
title = {Regeneration growth in different light environments of mixed species, multiaged, mountainous forests of Romania},
volume = {125},
issn = {1612-4669, 1612-4677},
url = {http://link.springer.com/10.1007/s10342-005-0069-3},
doi = {10.1007/s10342-005-0069-3},
pages = {151--162},
number = {2},
journaltitle = {European Journal of Forest Research},
author = {Stancioiu, Petru Tudor and O'Hara, Kevin L.},
date = {2006-05},
langid = {english}
}
\end{filecontents}
%_______________Zitate__________________________%
\usepackage[
style =authoryear,
natbib=true,
sorting=nyt,
maxcitenames=2,
mincitenames=1,
maxbibnames=30,
minbibnames=30,
hyperref=true,
dashed=false,
abbreviate=false,
uniquelist=false, %
uniquename=false,
backend=biber
]{biblatex}
\addbibresource{shortbib.bib}
% To make et al italic:
\renewbibmacro*{name:andothers}{% Based on name:andothers from biblatex.def
\ifboolexpr{
test {\ifnumequal{\value{listcount}}{\value{liststop}}}
and
test \ifmorenames
}
{\ifnumgreater{\value{liststop}}{1}
{\finalandcomma}
{}%
\andothersdelim\bibstring[\emph]{andothers}}
{}}
\AtEveryBibitem{%
\clearfield{note}% Delete all 'note' fields
\clearfield{day}% Delete all 'day' fields
\clearfield{month}% Delete all 'month' fields
}
\renewcommand*{\nameyeardelim}{\addspace} %To remove comma between author and year
\ExecuteBibliographyOptions{url=false, doi=true}
\renewcommand*{\mkbibnamelast}[1]{\textsc{#1}}
\renewcommand{\mkbibnamefamily}[1]{\textsc{#1}}
\renewcommand{\finalnamedelim}{ & } % ampersand instead and
\usepackage{hyperref}
\hypersetup{
colorlinks
,citecolor=blue
,linkcolor=yellow
,urlcolor=red
}
\ifpdftex{
\usepackage[T1]{fontenc}
\usepackage[ngerman=ngerman-x-latest]{hyphsubst}
}{
\usepackage{fontspec}
%\setmainfont{Charis SIL}
}
\usepackage{babel}
\begin{document}
As \textcite[p.~1]{greenwade93} already stated \autocite[cf.][p.~2]{stancioiu2006}, this is just an example \parencite{petritan2010}.
%_______________Bibliography__________________________%
\renewcommand*{\mkbibnamefamily}[1]{\fontfamily{phv}\selectfont \textsc{\textbf{#1}}}
\printbibliography[title={Index of sources}]
%_______________End__________________________%
\end{document}
biblatexembeds into the citation, so the most natural way would be to extend the link area. This is what the answer in Ulrike's link shows. Getting this right in general is quite tricky, but forauthoryearthe code is not too bad. In theory an alternative would be to colour the citations without applying any links, which would also not be too complicated, but adding links feels nicer. – moewe Jul 01 '20 at 16:10natbibbefore, I can still use thenatbibcommands without a problem! Only thing that comes to my attention:\citet{ammer_methoden_2004}produces the desired result, with "Ammer et al. (2004), all in blue. But the next sentence starts wit\citet[p.~8]{ammer_zur_2005}--> Ammer et al. (2005, p. 8). Here, only the year is blue. This is a bit striking, since a few words before all has been blue. Is there any way to have author and year blue, while [pre][post] extensions remain black? – Qiyuan Jul 02 '20 at 09:46authoryear-comp, is creating the opposite.\citet{ammer_2005}-> all blue.\citet[p.~1{ammer_2005}-> Author and year blue (Hurra) But:\citep[See][p~3]{ammer_2005}-> Here, regardless of the use of[pre]or[post]alone, together or not at all, only the year is blue. – Qiyuan Jul 02 '20 at 10:08(cite)style=authoryear,which is used in the question, if you want a solution forauthoryear-compthe solution will have to look different, but the same strategy can be applied). – moewe Jul 03 '20 at 07:46p.~in\textcite[p.~1]{greenwade93}.biblatexcan automatically detect page (ranges) and add "p."/"pp." as appropriate, so\textcite[1]{greenwade93}is generally preferable. It is worth keeping in mind thatfinalnamedelimis now a context-sensitive delimiter that should be redefined with\DeclareDelimFormat. I'd also prefer explicit\addspace/\spacecalls over simple spaces. So instead of\renewcommand{\finalnamedelim}{ \& }I'd have\DeclareDelimFormat{finalnamedelim}{\addspace\&\space}. – moewe Jul 03 '20 at 07:49style=authoryear,sorting=nyt,is already pre-set, so you don't have to mention it explicitly. Thebiblatexoptionhyperref=true,is usually not more useful than the presethyperref=auto,both produce links if and only if\usepackage{hyperref}is loaded, the only difference is thathyperref=true,emits a warning ifbiblatexdetects that\usepackage{hyperref}wasn't loaded. Generally\usepackage{hyperref}should be loaded last (save for a few exceptions -fontenc,fontspec,babelare not amongst them). – moewe Jul 03 '20 at 07:52\DeclareDelimFormatover\renewcommand, where would you look? In R, I just mark the command, press F1 and open the help menu. In TexStudio, when I hover over the command, sometimes a brief help openspar->15.1 \par. But how can I read the full version? Yes, thanks, I just realized yesterday that I don't need to writep~:D Is it adding a protected space? – Qiyuan Jul 03 '20 at 10:35authoryear, so it's working perfectly! …But 95% of the commands are ‘unknown command’s and have a threatening red background. But, another miracle of TexStudio/Latex, the desired results have been achieved, indicating that it somehow still works. ... I exchanged my version with yours using\DeclareDelimFormat. So far it looks identical. Thank you very much for your help! It is exactly what I wanted! – Qiyuan Jul 03 '20 at 10:35biblatexdocumentation (http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf). You should be able to get the documentation up on your screen by runningtexdoc biblatexin the command line (texdoc --view biblatexon MikTeX). Yes, by default the space thatbiblatexadds between the page prefix and the number is not breakable (look up\ppspacein the documentation to find out more). ... – moewe Jul 03 '20 at 11:40