-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
To latex position #35284
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
To latex position #35284
Changes from 8 commits
846a239
704202f
d3518de
8e30e11
a0b1bc4
940213c
fff3559
f3b9816
c33bfcf
4fd1539
d22d7ee
bd55f50
92ee692
644bdf7
31330d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,7 @@ def __init__( | |
multirow: bool = False, | ||
caption: Optional[str] = None, | ||
label: Optional[str] = None, | ||
position: Optional[str] = None, | ||
): | ||
self.fmt = formatter | ||
self.frame = self.fmt.frame | ||
|
@@ -50,6 +51,7 @@ def __init__( | |
self.caption = caption | ||
self.label = label | ||
self.escape = self.fmt.escape | ||
self.position = position | ||
|
||
def write_result(self, buf: IO[str]) -> None: | ||
""" | ||
|
@@ -284,8 +286,13 @@ def _write_tabular_begin(self, buf, column_format: str): | |
<https://en.wikibooks.org/wiki/LaTeX/Tables>`__ e.g 'rcl' | ||
for 3 columns | ||
""" | ||
if self.caption is not None or self.label is not None: | ||
if ( | ||
self.caption is not None | ||
or self.label is not None | ||
or self.position is not None | ||
): | ||
# then write output in a nested table/tabular environment | ||
buf.write(f"\\begin{{table}}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any obvious reason why this was moved up here? I would find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I did this was only because the line was getting too long, but I can write it as it was for sure. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I do find it more readable - but if you want to break the line, you could do so at
Wow... indeed the difference between |
||
if self.caption is None: | ||
caption_ = "" | ||
else: | ||
|
@@ -296,7 +303,12 @@ def _write_tabular_begin(self, buf, column_format: str): | |
else: | ||
label_ = f"\n\\label{{{self.label}}}" | ||
|
||
buf.write(f"\\begin{{table}}\n\\centering{caption_}{label_}\n") | ||
if self.position is None: | ||
position_ = "" | ||
else: | ||
position_ = f"[{self.position}]" | ||
|
||
buf.write(f"{position_}\n\\centering{caption_}{label_}\n") | ||
else: | ||
# then write output only in a tabular environment | ||
pass | ||
|
@@ -317,7 +329,11 @@ def _write_tabular_end(self, buf): | |
""" | ||
buf.write("\\bottomrule\n") | ||
buf.write("\\end{tabular}\n") | ||
if self.caption is not None or self.label is not None: | ||
if ( | ||
self.caption is not None | ||
or self.label is not None | ||
or self.position is not None | ||
): | ||
buf.write("\\end{table}\n") | ||
else: | ||
pass | ||
|
@@ -337,7 +353,11 @@ def _write_longtable_begin(self, buf, column_format: str): | |
<https://en.wikibooks.org/wiki/LaTeX/Tables>`__ e.g 'rcl' | ||
for 3 columns | ||
""" | ||
buf.write(f"\\begin{{longtable}}{{{column_format}}}\n") | ||
if self.position is None: | ||
position_ = "" | ||
else: | ||
position_ = f"[{self.position}]" | ||
buf.write(f"\\begin{{longtable}}{position_}{{{column_format}}}\n") | ||
|
||
if self.caption is not None or self.label is not None: | ||
if self.caption is None: | ||
|
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.
As this test grows, it would be better to have
self._table_float = any([p is not None for p in (caption, label, position)])
inside__init__.py
, to be used both here and in_write_tabular_end
.