biblatex-gb7714-2015 icon indicating copy to clipboard operation
biblatex-gb7714-2015 copied to clipboard

用法:关于不同字体下使用list类的文献表环境的缩进格式差异问题

Open hushidong opened this issue 4 years ago • 4 comments

我想把整个文献的字体都用中文字体表示,但发现使用list类的文献表环境是存在缩进格式问题。使用不同的字体会看到结果是不同的。

比如:

` \documentclass{article} \usepackage{ctex} \usepackage{hyperref} \usepackage[backend=biber,style=gb7714-2015,%url=false,% %gbnamefmt=lowercase,backref=false,% gbalign=right, doi=false,isbn=false,gbnoauthor=true,% maxnames=3,minnames=1]{biblatex}

\usepackage{filecontents} \begin{filecontents}{\jobname.bib} @Article{liu-2019-zh, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-en, title = {progress on accleration algorithm of the coputattion for chemical reactions in turbulent comubstion simulation}, journal = {Journal of Experiments in Fluid Mechanics}, author ={Liu, Zai Gang and Kong, Wen Jun}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{Myburg2014-356-362, author = {Myburg, Alexander A. and Grattapaglia, Dario and Tuskan, Gerald A. and others}, title = {The genome of Eucalyptus grandis}, journal = {Nature}, year = {2014}, date = {2014-06-19}, volume = {510}, pages = {356--362}, doi = {10.1038/nature13308}, url = {http://www.nature.com/nature/journal/v510/n7505/pdf/nature13308.pdf}, urldate = {2014-06-25}, }

@article{choi_pricing_1985, title = {Pricing options on agricultural futures: An application of the constant elasticity of variance option pricing model}, volume = {5}, rights = {Copyright © 1985 Wiley Periodicals, Inc., A Wiley Company}, issn = {1096-9934}, url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/fut.3990050208}, doi = {10.1002/fut.3990050208}, shorttitle = {Pricing options on agricultural futures}, pages = {247--258}, number = {2}, journaltitle = {Journal of Futures Markets}, author = {Choi, Jin W. and Longstaff, Francis A.}, urldate = {2018-10-15}, date = {1985-06-01}, langid = {english}, file = {Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:F:\research\paper\zotero\files\storage\P7VXIY5I\Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:application/pdf} } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

{ %方法一 % 全局字体 %\renewcommand{\bibfont}{\zihao{5}\songti}%\fangsong % 题名字体 %\renewcommand{\bibauthorfont}{\bfseries\color{teal}}% %\renewcommand{\bibtitlefont}{\ttfamily\color{blue}}% %\renewcommand{\bibpubfont}{\itshape\color{violet}}% % url和doi字体 %\def\UrlFont{\ttfamily} %\urlstyle{sf} %\def\UrlFont{\bfseries} % 竖直间距的控制 \setlength{\bibitemsep}{0ex} \setlength{\bibnamesep}{0ex} \setlength{\bibinitsep}{0ex} %行距正常情况下是由文档的设置来设定的,比如\linespread,\baselinestretch等命令,以及zhlineskip宏包等。

%方法二 %字体和行距也直接设置比如: %而且这种设置 \newcommand{\ftsongti}{\fontspec{FangSong}\selectfont}%NSimSun,FangSong,SimHei,KaiTi,LiSu,YouYuan %\newfontfamily\ftsongti{simfang.ttf} %\newcommand{\ftsongti}{\fontspec{Source Sans Pro}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolHei}\selectfont} %\newcommand{\ftsongti}{\fontspec{DengXian}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolFang}\selectfont} %\newcommand{\ftsongti}{\fontspec{Microsoft YaHei}\selectfont} \newCJKfontfamily\ftsongticjk{simfang.ttf} \renewcommand{\bibfont}{\ftsongticjk\ftsongti}%\fangsong15.75pt \ftsongti \def\UrlFont{\ftsongti}

%\fontsize{10.5pt}{14.5pt}\selectfont

\printbibliography

}

\end{document} `

结果为:

图片

显然,这是有问题,试了几中字体发现是不一样的。找了几种原因,以为是字体定义导致的,采用多种字体设置后发现还是存在问题,说明不是,那是不是环境的问题,所以试了一下list环境。如下

hushidong avatar Mar 16 '20 12:03 hushidong

` \documentclass{article} \usepackage{ctex} \usepackage{hyperref} \usepackage[paperheight=15cm,paperwidth=15cm,showframe]{geometry}

\newcounter{figb} \newenvironment{figlist} {\list {\makebox{[\arabic{figb}]}} {\usecounter{figb} \setlength{\labelwidth}{10pt} \setlength{\labelsep}{5pt} %\setlength{\leftmargin}{\labelwidth}% %\addtolength{\leftmargin}{5pt} \setlength{\leftmargin}{0pt}% \setlength{\itemindent}{0pt}% \setlength{\itemsep}{2pt}% \setlength{\parsep}{1ex}}% \renewcommand*{\makelabel}[1]{\hss##1}}%环境开始定义代码(begin code) {\endlist}%环境结束定义代码(end code)

\begin{document}

\noindent 段落段落

\newcommand{\ftsongti}{\fontspec{FangSong}\selectfont}%FangSongSource Sans Pro \newCJKfontfamily\ftsongticjk{simfang.ttf}

{ \ftsongti\ftsongticjk \begin{figlist} \item 刘再刚, 孔文俊. 湍流燃烧模拟中化学反应的加速算法研究进展[J]. 实验流体力学, 2019, 33(4):1-10.

\item LIU Z G, KONG W J. Progress on accleration algorithm of the coputattion for chemical reactions in turbulent comubstion sim- ulation[J]. Journal of Experiments in Fluid Mechanics, 2019, 33(4):1-10.

\end{figlist}

}

\end{document} `

结果为: 图片

从结果看,显然也存在问题,采用不同的字体后也是一样的,这说明是list环境中的问题,无关biblatex。所以还是要分析现象,从list环境防标签的原理可以知道,当标签在labelwidth放不下时,会自动超出标签盒子宽度,说明是盒子宽度的问题。

所以重新设置盒子的宽度为20pt,那么结果为:

\setlength{\labelwidth}{20pt} 图片

这样我们找到了原因,那么要去看看biblatex中的问题。

hushidong avatar Mar 16 '20 12:03 hushidong

类似的,由于biblatex中\labelnumberwidth是一个随时计算的变量,无法在list环境外设置,那么需要在list环境内修改,比如:

\defbibenvironment{bibliography}
  {\list
     {\printtext[labelnumberwidth]{%
        \printfield{labelprefix}%
        \printfield{labelnumber}}}
     {\addtolength{\labelnumberwidth}{5pt}
     %使标签盒子宽度增加5pt,不同的字体需要的量是不同的。
     \setlength{\labelwidth}{\labelnumberwidth}%
      \setlength{\labelsep}{\biblabelsep}%
      \setlength{\leftmargin}{\bibhang}%
      \addtolength{\leftmargin}{\labelnumberwidth}%
      %\showthe\biblabelsep
      %\showthe\labelnumberwidth
      %\showthe\leftmargin
      \setlength{\itemindent}{\bibitemindent}%
      \setlength{\itemsep}{\bibitemsep}%
      \setlength{\parsep}{\bibparsep}}%
      \renewcommand*{\makelabel}[1]{\hss##1}}
  {\endlist}
  {\item}

因此,测试例子, ` \documentclass{article} \usepackage{ctex} \usepackage{hyperref} \usepackage[backend=biber,style=gb7714-2015,%url=false,% %gbnamefmt=lowercase,backref=false,% gbalign=right, doi=false,isbn=false,gbnoauthor=true,% maxnames=3,minnames=1]{biblatex}

\defbibenvironment{bibliography} {\list {\printtext[labelnumberwidth]{% \printfield{labelprefix}% \printfield{labelnumber}}} {\addtolength{\labelnumberwidth}{5pt} %使标签盒子宽度增加5pt,不同的字体需要的量是不同的。 \setlength{\labelwidth}{\labelnumberwidth}% \setlength{\labelsep}{\biblabelsep}% \setlength{\leftmargin}{\bibhang}% \addtolength{\leftmargin}{\labelnumberwidth}% %\showthe\biblabelsep %\showthe\labelnumberwidth %\showthe\leftmargin \setlength{\itemindent}{\bibitemindent}% \setlength{\itemsep}{\bibitemsep}% \setlength{\parsep}{\bibparsep}}% \renewcommand*{\makelabel}[1]{\hss##1}} {\endlist} {\item}

\usepackage{filecontents} \begin{filecontents}{\jobname.bib} @Article{liu-2019-zh, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh1, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh2, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh3, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh4, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh5, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh6, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh7, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh8, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh9, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh10, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-zh11, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-en, title = {progress on accleration algorithm of the coputattion for chemical reactions in turbulent comubstion simulation}, journal = {Journal of Experiments in Fluid Mechanics}, author ={Liu, Zai Gang and Kong, Wen Jun}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{Myburg2014-356-362, author = {Myburg, Alexander A. and Grattapaglia, Dario and Tuskan, Gerald A. and others}, title = {The genome of Eucalyptus grandis}, journal = {Nature}, year = {2014}, date = {2014-06-19}, volume = {510}, pages = {356--362}, doi = {10.1038/nature13308}, url = {http://www.nature.com/nature/journal/v510/n7505/pdf/nature13308.pdf}, urldate = {2014-06-25}, }

@article{choi_pricing_1985, title = {Pricing options on agricultural futures: An application of the constant elasticity of variance option pricing model}, volume = {5}, rights = {Copyright © 1985 Wiley Periodicals, Inc., A Wiley Company}, issn = {1096-9934}, url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/fut.3990050208}, doi = {10.1002/fut.3990050208}, shorttitle = {Pricing options on agricultural futures}, pages = {247--258}, number = {2}, journaltitle = {Journal of Futures Markets}, author = {Choi, Jin W. and Longstaff, Francis A.}, urldate = {2018-10-15}, date = {1985-06-01}, langid = {english}, file = {Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:F:\research\paper\zotero\files\storage\P7VXIY5I\Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:application/pdf} } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

{ %方法一 % 全局字体 %\renewcommand{\bibfont}{\zihao{5}\songti}%\fangsong % 题名字体 %\renewcommand{\bibauthorfont}{\bfseries\color{teal}}% %\renewcommand{\bibtitlefont}{\ttfamily\color{blue}}% %\renewcommand{\bibpubfont}{\itshape\color{violet}}% % url和doi字体 %\def\UrlFont{\ttfamily} %\urlstyle{sf} %\def\UrlFont{\bfseries} % 竖直间距的控制 \setlength{\bibitemsep}{0ex} \setlength{\bibnamesep}{0ex} \setlength{\bibinitsep}{0ex} %行距正常情况下是由文档的设置来设定的,比如\linespread,\baselinestretch等命令,以及zhlineskip宏包等。

%方法二 %字体和行距也直接设置比如: %而且这种设置 \newcommand{\ftsongti}{\fontspec{FangSong}\selectfont}%NSimSun,FangSong,SimHei,KaiTi,LiSu,YouYuan %\newfontfamily\ftsongti{simfang.ttf} %\newcommand{\ftsongti}{\fontspec{Source Sans Pro}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolHei}\selectfont} %\newcommand{\ftsongti}{\fontspec{DengXian}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolFang}\selectfont} %\newcommand{\ftsongti}{\fontspec{Microsoft YaHei}\selectfont} %\newCJKfontfamily\ftsongticjk{simfang.ttf} \renewcommand{\bibfont}{\fangsong\ftsongti}%\fangsong15.75pt \ftsongti \def\UrlFont{\ftsongti}

%\fontsize{10.5pt}{14.5pt}\selectfont

\printbibliography

}

\end{document} `

结果为:

图片

显然,找到了解决方法,那么其核心原因是,biblatex在计算\labelnumberwidth时,使用默认的字体,比如罗马字体时,其计算逻辑得到的labelnumberwidth是足够的,但使用中文字体时,其labelnumberwidth似乎就不够了,暂时我没有深入去研究labelnumberwidth的计算逻辑,不知道是什么细节上,导致labelnumberwidth宽度不够了。

当然现在,我们已经知道解决方案了,就是重定义bibliography环境就可以了。

hushidong avatar Mar 16 '20 13:03 hushidong

当然这是使用了list类环境所出现的问题,当不使用这种方法时,比如使用项对齐的方式,就不会有这种问题,也不用调整。

` \documentclass{article} \usepackage{ctex} \usepackage{hyperref} \usepackage[backend=biber,style=gb7714-2015,%url=false,% %gbnamefmt=lowercase,backref=false,% gbalign=gb7714-2015, doi=false,isbn=false,gbnoauthor=true,% maxnames=3,minnames=1]{biblatex}

\usepackage{filecontents} \begin{filecontents}{\jobname.bib} @Article{liu-2019-zh, title = {湍流燃烧模拟中化学反应的加速算法研究进展}, journal = {实验流体力学}, author ={刘再刚 and 孔文俊}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{liu-2019-en, title = {progress on accleration algorithm of the coputattion for chemical reactions in turbulent comubstion simulation}, journal = {Journal of Experiments in Fluid Mechanics}, author ={Liu, Zai Gang and Kong, Wen Jun}, year = {2019}, volume = {33}, number = {4}, pages = {1-10} }

@Article{Myburg2014-356-362, author = {Myburg, Alexander A. and Grattapaglia, Dario and Tuskan, Gerald A. and others}, title = {The genome of Eucalyptus grandis}, journal = {Nature}, year = {2014}, date = {2014-06-19}, volume = {510}, pages = {356--362}, doi = {10.1038/nature13308}, url = {http://www.nature.com/nature/journal/v510/n7505/pdf/nature13308.pdf}, urldate = {2014-06-25}, }

@article{choi_pricing_1985, title = {Pricing options on agricultural futures: An application of the constant elasticity of variance option pricing model}, volume = {5}, rights = {Copyright © 1985 Wiley Periodicals, Inc., A Wiley Company}, issn = {1096-9934}, url = {https://onlinelibrary.wiley.com/doi/abs/10.1002/fut.3990050208}, doi = {10.1002/fut.3990050208}, shorttitle = {Pricing options on agricultural futures}, pages = {247--258}, number = {2}, journaltitle = {Journal of Futures Markets}, author = {Choi, Jin W. and Longstaff, Francis A.}, urldate = {2018-10-15}, date = {1985-06-01}, langid = {english}, file = {Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:F:\research\paper\zotero\files\storage\P7VXIY5I\Choi_Longstaff_1985_Pricing options on agricultural futures.pdf:application/pdf} } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\nocite{*}

{ %方法一 % 全局字体 %\renewcommand{\bibfont}{\zihao{5}\songti}%\fangsong % 题名字体 %\renewcommand{\bibauthorfont}{\bfseries\color{teal}}% %\renewcommand{\bibtitlefont}{\ttfamily\color{blue}}% %\renewcommand{\bibpubfont}{\itshape\color{violet}}% % url和doi字体 %\def\UrlFont{\ttfamily} %\urlstyle{sf} %\def\UrlFont{\bfseries} % 竖直间距的控制 \setlength{\bibitemsep}{0ex} \setlength{\bibnamesep}{0ex} \setlength{\bibinitsep}{0ex} %行距正常情况下是由文档的设置来设定的,比如\linespread,\baselinestretch等命令,以及zhlineskip宏包等。

%方法二 %字体和行距也直接设置比如: %而且这种设置 \newcommand{\ftsongti}{\fontspec{FangSong}\selectfont}%NSimSun,FangSong,SimHei,KaiTi,LiSu,YouYuan %\newfontfamily\ftsongti{simfang.ttf} %\newcommand{\ftsongti}{\fontspec{Source Sans Pro}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolHei}\selectfont} %\newcommand{\ftsongti}{\fontspec{DengXian}\selectfont} %\newcommand{\ftsongti}{\fontspec{FandolFang}\selectfont} %\newcommand{\ftsongti}{\fontspec{Microsoft YaHei}\selectfont} %\newCJKfontfamily\ftsongticjk{simfang.ttf} \renewcommand{\bibfont}{\fangsong\ftsongti}%\fangsong15.75pt \ftsongti \def\UrlFont{\ftsongti}

%\fontsize{10.5pt}{14.5pt}\selectfont

\printbibliography

}

\end{document} `

结果为:

图片

hushidong avatar Mar 16 '20 13:03 hushidong

增加一个尺寸,以在出现label宽度不够时可以调整,避免list类环境的缩进错误。 见:https://github.com/hushidong/biblatex-gb7714-2015/commit/dd82a37a26807733ea5f3b2fc612fdfc14a017be

hushidong avatar Mar 19 '20 12:03 hushidong