
我想要由套件控制的文件中的日期語言。這似乎datetime2
是唯一做這種事的現代包。但是,有時我只需要顯示日和月,而不顯示年份,即
21th March
那可能嗎?我知道有一個未記錄的(!)showdayofmonth
標誌(Latex 中的月/年格式)當天就可以做到這一點,但我找不到當年的類似內容。
也許我應該嘗試另一個包?或許babel
?你有什麼建議?
微量元素
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}
\begin{document}
\DTMDisplaydate{0}{2}{10}{-1}
\end{document}
答案1
編輯:有一個未記錄的showyear
密鑰。您可以使用例如將其應用於單一語言\DTMsetbool{en-GB}{showyear}{false}
,或使用使用的所有語言\DTMlangsetup{showyear=false}
。第二個版本發出警告,因為該金鑰不適用於層次結構中的某些區域,例如english-base
.可以使用以下方法抑制此警告\DTMlangsetup*
(請參閱datetime2 -- 使用 showyear 設定時的警告)。
\DTMDisplaydate
此設定會變更整個文件的行為,但您可以在使用後重設它。
微量元素:
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}
\begin{document}
\DTMlangsetup*{showyear=false}
\DTMDisplaydate{2020}{2}{10}{-1} is the date
\DTMlangsetup*{showyear=true}
\DTMDisplaydate{2020}{2}{10}{-1} is the date
\end{document}
結果:
原答案:
您可以定義不帶年份的新日期格式,例如手動的(例如,第 96 頁及更多)。
當您想使用新格式時,您需要使用它來設定它,\DTMsetdatestyle
這會影響\DTMDisplaydate
.似乎不可能將其設定為僅用於單次使用,因此之後您需要將樣式重設為先前的樣式,在MWE中這是en-GB
(因為main=british
)。請注意,您需要新增calc
套件選項才能datetime2
使用\DTMmonthname
巨集。
微量元素:
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional,calc]{datetime2}
\begin{document}
\DTMnewdatestyle{noyear}{%
\renewcommand{\DTMdisplaydate}[4]{%
\DTMenglishordinal{##3} \DTMmonthname{##2}}%
}
\DTMsetdatestyle{noyear}
\DTMDisplaydate{2020}{2}{10}{-1}
\DTMsetdatestyle{en-GB}
\DTMDisplaydate{2020}{2}{10}{-1}
\end{document}
結果:
請注意,重新定義包括\DTMenglishordinal
為了防止序數 (th) 被列印為上標。更國際化的版本\ordinalnum
來自fmtcount
套件(支援多種歐洲語言),但據我所知僅作為上標。
答案2
我介紹\stripyear
來幫忙。
\documentclass{scrbook}
\usepackage[english,main=british]{babel}
\usepackage[useregional]{datetime2}
\newcommand\stripyear[1]{%
\edef\tmp{#1}\expandafter\stripyearaux\tmp\relax}
\def\stripyearaux#1 #2 #3\relax{#1 #2}
\begin{document}
\stripyear{\DTMDisplaydate{2020}{2}{10}{-1}}.
\end{document}