-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add latex key to configure literal blocks caption position in PDF output #3872
Conversation
According to ``literalblockcappos`` setting in ``'sphinxsetup'``, (t)op or (b)ottom, the caption will be typeset before or after the literal block. If typeset above, its distance to frame is now identical to the setting used for captions of tables (one half of the baseline). Further keys ``verbatimcontinuedalign`` and ``verbatimcontinuesalign`` allow to horizontally align the continuation hints relative to the literal block contents: either (l)eft, (c)enter, or (r)ight.
@@ -189,14 +189,25 @@ The available styling options | |||
default ``true``. Tells whether long lines in :rst:dir:`code-block`\ 's | |||
contents should wrap. | |||
|
|||
``literalblockcappos`` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be related with #1723. But the proper way is not discussed yet. So let's go ahead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, this PR partially addresses #1723 but only for code-blocks and only for PDF output. It is thus not complete feature.
thanks for review, now merging, I am online for a few days.
With
literalblockcappos=b
added to'sphinxsetup'
, the captions of literal blocks are typeset after the literal block in PDF output. Default ist
which says to typeset them above.Also added
verbatimcontinuedalign
andverbatimcontinuesalign
with possible valuesl, c, r
for alignment of continuation hints with respect to literal block contents (relates #3792). This gives for example:The
verbatimhintsturnover
default is nowtrue
so that at 1.7 continuation hints (internationalized) will be the default.Details
In case the caption is printed after the literal block, nevertheless the internal links will be set up to point to start of literal block.
The caption width is now wrapped to the same maximal width as for table captions: the
\LTcapwidth
parameter whose default is4in
.I have considered horizontal alignment of the caption itself. This can be done indeed for literal blocks, but I dropped it because it is not easy to do the similar thing for tables:
Hence I dropped horizontal alignment for caption of literal blocks.
In future, if a global config setting is added for caption placement, this PR does it already for literal blocks, so this will facilitate implementation. For tables, it is already not too complicated thanks to the templates. For figures, some refactoring is needed first.
The
\sphinxcaption
which is used for tables (except longtable) and with this PR for literal blocks too has been made more flexible: earlier it hard-coded reset of\abovecaptionskip/\belowcaptionskip
to0pt
for uniform treatement of tables, now the two are reset to values given by some user modifiable macros.If caption is on top the distance from baseline of caption text to frame of literal block is now same value as for table captions (
\sphinxbelowcaptionspace
whose default is6pt = 0.5\baselineskip = \parskip
). This is slightly increase from previous setting, in order to get uniformity with table caption placement.More generally, the vertical spacing for literal blocks is now customizable via renewcommand of latex macros (see next).
Memo on vertical spacing
Here are the default values for vertical spacing (in English documents):
tables:
\baselineskip (12pt) + \parskip (6pt) + \sphinxtablepre (0pt) = 18pt
from baseline of text to top of table,18pt
to top of caption (i.e.\ht\strutbox = 8.4pt
above caption text baseline),12pt+6pt+\sphinxtablepost(=\medskipamount=6pt) = 24pt
from table bottom frame to next text baseline.literal blocks:
\sphinxverbatimsmallskipamount (=\smallskipamount=3pt) + \baselineskip (12pt) - \FrameHeightAdjust (default 6pt) = 9pt
from baseline of previous text to top of block frame,\abovecaptionskip (10pt) + same (12 pt - 6pt) = 16pt
from baseline of previous text to top of caption,\baselineskip+\parskip=18pt
from bottom frame to next text baseline.These values were already the ones theoretically for literal blocks before this PR, but for a reason I have not fully understood, in case with caption I measured a bit smaller on stable branch, perhaps
15pt
, not the16pt
. Perhaps some stretch-shrink which is now not rendered due to refactoring of latex macros.Compared to tables, literal blocks are less separated from ambient text, and in cse of caption there is much less difference between "before" and "after" spaces.
Note: all this is now customizable easily except the spacing after literal block, there is no hook to customize it, contrarily to tables. This can be added later if a need arises.
(regarding literal block top vertical spacing, it was reduced in #2460)
Relates
#3792, #2460, #3504
and #1723