Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save trueroad/80630e95df5af0234e36270b019e6458 to your computer and use it in GitHub Desktop.
Save trueroad/80630e95df5af0234e36270b019e6458 to your computer and use it in GitHub Desktop.
参考文献の行長を字幅の整数倍にする
\documentclass[twocolumn]{jlreq}
\makeatletter
\renewenvironment{thebibliography}[1]{%
\jlreq@oldfontcommand@enable
\section*{\refname}%
\@mkboth{\refname}{\refname}%
\list{\@biblabel{\@arabic\c@enumiv}}%
{\settowidth\labelwidth{\@biblabel{#1}}%
\@tempdima\linewidth
\advance\@tempdima-\labelwidth
\advance\@tempdima-\labelsep
\@tempdimb\@tempdima
\@tempdimc 1\zw
\divide\@tempdima\@tempdimc
\multiply\@tempdima\@tempdimc
\advance\@tempdimb-\@tempdima
\advance\labelsep\@tempdimb
\leftmargin\labelwidth
\advance\leftmargin\labelsep
\itemindent=0pt
\@openbib@code
\usecounter{enumiv}%
\let\p@enumiv\@empty
\renewcommand\theenumiv{\@arabic\c@enumiv}}%
\sloppy
\clubpenalty4000
\@clubpenalty\clubpenalty
\widowpenalty4000%
\sfcode`\.\@m
}{%
\def\@noitemerr{\@latex@warning{Empty `thebibliography' environment}}%
\endlist
\jlreq@oldfontcommand@disable
}
\makeatother
\begin{document}
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
\fontsize{9pt}{12pt}\selectfont
\begin{thebibliography}{9}
\bibitem{one}
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
\bibitem{two}
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
□□□□□□□□□■□□□□□□□□□■□□□□□□□□□■
\bibitem{three}
textwidth: \the\textwidth, linewidth: \the\linewidth,
labelwidth: \the\labelwidth, labelsep: \the\labelsep,
labelwidth+labelsep:
\newlength{\templength}\setlength{\templength}{\labelwidth}
\addtolength{\templength}{\labelsep}\the\templength,
leftmargin: \the\leftmargin, zw:
\newlength{\tempzw}\setlength{\tempzw}{1\zw} \the\tempzw.
\end{thebibliography}
\end{document}
@trueroad
Copy link
Author

これまで LuaLaTeX のみで動作テストしており、
pLaTeX で動作しないようになっていたので、
どちらでも動作するように修正しました。

@yuw
Copy link

yuw commented Apr 12, 2018

すばらしい!可変になってる!
s/\advance\labelwidth@tempdimb/\advance\labelsep@tempdimb/
とすると,左端が揃っていいかもしれません.
pLaTeXは\zwがひっかかりますかね.
だとすると,適当なタイミングで和字一文字分のサイズを取得して,それを用いるとよい想像します :-)

@trueroad
Copy link
Author

コメントありがとうございます。

元々の @yuw さんの実装では \labelwidth を補正していたので、
それを踏襲して \labelwidth を補正するようにしていたのですが、
文献番号の左端を本文の左端と揃えるなら、仰る通り \labelsep の補正にした方がいいですね。
というわけで変更してみました。

pLaTeX, LuaLaTeX 両対応です。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment