Repository navigation
Add latex key to configure literal blocks caption position in PDF output - #3872
Merged
Merged
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.
tk0miya
approved these changes
Jul 17, 2017
| default ``true``. Tells whether long lines in :rst:dir:`code-block`\ 's | ||
| contents should wrap. | ||
|
|
||
| ``literalblockcappos`` |
Member
There was a problem hiding this comment.
This might be related with #1723. But the proper way is not discussed yet. So let's go ahead.
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
literalblockcappos=badded to'sphinxsetup', the captions of literal blocks are typeset after the literal block in PDF output. Default istwhich says to typeset them above.Also added
verbatimcontinuedalignandverbatimcontinuesalignwith possible valuesl, c, rfor alignment of continuation hints with respect to literal block contents (relates #3792). This gives for example:The
verbatimhintsturnoverdefault is nowtrueso 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
\LTcapwidthparameter 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
\sphinxcaptionwhich 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/\belowcaptionskipto0ptfor 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 (
\sphinxbelowcaptionspacewhose 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) = 18ptfrom baseline of text to top of table,18ptto top of caption (i.e.\ht\strutbox = 8.4ptabove caption text baseline),12pt+6pt+\sphinxtablepost(=\medskipamount=6pt) = 24ptfrom table bottom frame to next text baseline.literal blocks:
\sphinxverbatimsmallskipamount (=\smallskipamount=3pt) + \baselineskip (12pt) - \FrameHeightAdjust (default 6pt) = 9ptfrom baseline of previous text to top of block frame,\abovecaptionskip (10pt) + same (12 pt - 6pt) = 16ptfrom baseline of previous text to top of caption,\baselineskip+\parskip=18ptfrom 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