问题
When I use Emacs calendar/diary with org-mode(however I do not think this is the reason of the problem), I encounter the following problem.
The default calendar is like this:

I add the following codes to display week number:
(copy-face font-lock-constant-face 'calendar-iso-week-face)
(set-face-attribute 'calendar-iso-week-face nil
:height 1)
(setq calendar-intermonth-text
'(propertize
(format "%2d"
(car
(calendar-iso-from-absolute
(calendar-absolute-from-gregorian (list month day year)))))
'font-lock-face 'calendar-iso-week-face))
; Title for week number
(copy-face 'default 'calendar-iso-week-header-face)
(set-face-attribute 'calendar-iso-week-header-face nil
:height 0.7)
(setq calendar-intermonth-header
(propertize "Wk" ; or e.g. "KW" in Germany
'font-lock-face 'calendar-iso-week-header-face))
After inserting these codes, the week numbers can be displayed. However, the alignment is a little bit strange like this:

The last line of the calendar is not aligned. How to deal with this problem?
Thanks.
回答1:
It's your height
settings that are causing the problem. You may wish to try experimenting with the other variables such as: calendar-left-margin
, calendar-column-width
, calendar-day-header-width
, calendar-day-digit-width
, calendar-intermonth-header
, calendar-intermonth-text
.
NOTE: For anyone wondering how to highlight Saturday instead of Monday, the function calendar-generate-month
has a line of code that contains (if (memq i '(0 6))
-- if calendar-week-start-day
is changed from 0
to 1
, then it would be necessary to alter the above-code from 0 6
to 5 6
. Alternatively, the font-lock settings can be trumped by adding new keywords for the days of the week.
(setq calendar-week-start-day 1)
(setq calendar-intermonth-text
'(propertize
(format "%2d"
(car
(calendar-iso-from-absolute
(calendar-absolute-from-gregorian (list month day year)))))
'font-lock-face 'font-lock-warning-face))
(setq calendar-intermonth-header
(propertize "Wk" ; or e.g. "KW" in Germany
'font-lock-face 'font-lock-keyword-face))
(source: lawlist.com)
来源:https://stackoverflow.com/questions/21364948/how-to-align-the-calendar-with-week-number-as-the-intermonth-text