! LaTeX 错误:命令 \textdegree 在编码 OT1 中不可用

! LaTeX 错误:命令 \textdegree 在编码 OT1 中不可用

找到解决方案

\usepackage{textcomp}允许使用\textdegree宏,感谢@Mico。


我使用 TeXmaker 作为编辑器,并使用 Mendeley 生成文件.bib。一个条目的标题中有一个度数符号。Mendeley 编码为 UTF-8,因此我使用

\usepackage[utf8]{inputenc}

但是度数符号似乎不起作用。我也尝试过包括

\usepackage[T1]{fontenc}

根据 stackexchange 上的一些建议,错误从 OT1 变为 T1。

我怎样才能让度数符号起作用?谢谢。


编辑-MWE(导致错误):

\documentclass[a4paper,12pt]{article}

% Text and Maths
\usepackage[utf8]{inputenc}                                 % Input accented characters from keyboard input


%References and page interlinking

\usepackage[numbers,sort&compress,super]{natbib}        % References - [numbers,sort&compress,super]
\bibliographystyle{unsrt}                                   % BibStyle - unsrt keeps 1,2,3 instead of 2,1,3 (?)

\usepackage[final]{hyperref}                                    % adds hyper links inside the generated pdf file
\hypersetup{
colorlinks=true,                                                    % false: boxed links; true: colored links
linkcolor=blue,                                                     % color of internal links
citecolor=blue,                                                     % color of links to bibliography
filecolor=magenta,                                              % color of file links
urlcolor=blue                                                       % colour of url link
}
\usepackage{cleveref}                                               % Clever ref - loaded AFTER hyperref!

\begin{document}

test
\citep{Zimmermann2009}

\bibliography{/Users/me/Documents/library.bib}
\end{document}

.bib我认为,错误是由标题中的度数符号引起的。

@article{Zimmermann2009,
abstract = {An unusual variety of magnetic, magnetoelectric and ferrotoroidic properties was observed in the lithium-orthophosphates LiMPO(4) with M = Fe, Co, Ni by optical second harmonic generation. In spite of a largely similar magnetic and crystallographic structure the compounds exhibit pronounced differences in the topology of antiferromagnetic 180A degrees domains. In LiCoPO(4) the antiferromagnetic domains coexist with ferrotoroidic, i.e., magnetic vortex domains. For LiNiPO(4) it was shown that the weak ferrimagnetic moment of the LiMPO(4) compounds along the spin direction is rigidly coupled to the AFM order parameter so that the sign of the magnetoelectric effect is reversed by a magnetic field only. Further effects of a static magnetic field on the system are discussed.},
author = {Zimmermann, A. S. and {Van Aken}, B. B. and Schmid, H. and Rivera, J. P. and Li, J. and Vaknin, D. and Fiebig, M.},
doi = {10.1140/epjb/e2009-00223-3},
file = {:Users/matt/Documents/Mendeley Desktop/Zimmermann et al. - 2009 - Anisotropy of antiferromagnetic 180° domains in magnetoelectric LiMPO 4 (M = Fe, Co, Ni).pdf:pdf},
isbn = {1434-6028},
issn = {14346028},
journal = {European Physical Journal B},
number = {3},
pages = {355--360},
title = {{Anisotropy of antiferromagnetic 180° domains in magnetoelectric LiMPO 4 (M = Fe, Co, Ni)}},
volume = {71},
year = {2009}
}

答案1

如果您想继续使用该natbib包和参考书目样式,您需要做的就是(a)用“ ”替换字段中的unsrt符号并(b)加载该包,因为它提供了宏。°title\textdegree\textcomptextdegree

以下代码应该可以顺利编译。(我通过删除unsrt参考书目样式忽略的字段来简化 bib 条目。)

\RequirePackage{filecontents}
\begin{filecontents}{mylibrary.bib}
@article{Zimmermann2009,
  author  = {Zimmermann, A. S. and Van Aken, B. B. and
            Schmid, H. and Rivera, J. P. and Li, J. and 
            Vaknin, D. and Fiebig, M.},
  journal = {European Physical Journal B},
  number  = {3},
  pages   = {355--360},
  title   = {{Anisotropy of antiferromagnetic 180\textdegree\ domains
            in magnetoelectric LiMPO~4 (M=Fe, Co, Ni)}},
  volume  = {71},
  year    = {2009}
}
\end{filecontents}

\documentclass[a4paper,12pt]{article}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{textcomp}% for '\textdegree' macro
\usepackage[sort&compress,super]{natbib} % no need to specify "numbers"
\bibliographystyle{unsrt}
\usepackage{hyperref}                                   
\hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,
    filecolor=magenta, urlcolor=blue}
\usepackage{cleveref}  

\begin{document}
test\citep{Zimmermann2009}
\bibliography{mylibrary}
\end{document}

附录:您可能不想将 pdfLaTeX 与fontencinputenctextcomp软件包一起使用,而是希望将 LuaLaTeX 与 软件包一起使用fontspec。如果您可以进行此切换,您将获得对 utf8-encode 符号的原生支持。

在此处输入图片描述

% !TeX program = lualatex

\RequirePackage{filecontents}
\begin{filecontents}{mylibrary.bib}
@article{Zimmermann2009,
abstract= {An unusual variety of magnetic, magnetoelectric and ferrotoroidic properties was observed in the lithium-orthophosphates LiMPO(4) with M = Fe, Co, Ni by optical second harmonic generation. In spite of a largely similar magnetic and crystallographic structure the compounds exhibit pronounced differences in the topology of antiferromagnetic 180A degrees domains. In LiCoPO(4) the antiferromagnetic domains coexist with ferrotoroidic, i.e., magnetic vortex domains. For LiNiPO(4) it was shown that the weak ferrimagnetic moment of the LiMPO(4) compounds along the spin direction is rigidly coupled to the AFM order parameter so that the sign of the magnetoelectric effect is reversed by a magnetic field only. Further effects of a static magnetic field on the system are discussed.},
author  = {Zimmermann, A. S. and {Van Aken}, B. B. and Schmid, H. and Rivera, J. P. and Li, J. and Vaknin, D. and Fiebig, M.},
doi     = {10.1140/epjb/e2009-00223-3},
file    = {:Users/mcolbear/Documents/Mendeley Desktop/Zimmermann et al. - 2009 - Anisotropy of antiferromagnetic 180° domains in magnetoelectric LiMPO 4 (M = Fe, Co, Ni).pdf:pdf},
isbn    = {1434-6028},
issn    = {14346028},
journal = {European Physical Journal~B},
number  = {3},
pages   = {355--360},
title   = {{Anisotropy of antiferromagnetic 180° domains in magnetoelectric LiMPO~4 (M = Fe, Co, Ni)}},
volume  = {71},
year    = {2009}
}
\end{filecontents}

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec} % don't load 'inputenc', 'fontenc', & 'textcomp' packages
\usepackage[sort&compress,super]{natbib} % no need to specify "numbers" option
\bibliographystyle{unsrt}
\usepackage{hyperref}                                   
\hypersetup{colorlinks=true,linkcolor=blue,citecolor=blue,
    filecolor=magenta, urlcolor=blue}
\usepackage{cleveref}  

\begin{document}
test\citep{Zimmermann2009}
\bibliography{mylibrary}
\end{document}

相关内容