diff options
13 files changed, 63 insertions, 21 deletions
@@ -85,6 +85,8 @@ Bugs fixed leak to the shadow and border at a page break * #11264: LaTeX: missing space before colon after "Voir aussi" for :rst:dir:`seealso` directive in French +* #11268: LaTeX: longtable with left alignment breaks out of current list + indentation context in PDF. Thanks to picnixz. * #11274: LaTeX: external links are not properly escaped for ``\sphinxupquote`` compatibility * #11147: Fix source file/line number info in object description content and in diff --git a/sphinx/templates/latex/longtable.tex.jinja b/sphinx/templates/latex/longtable.tex.jinja index f5cb522ce..3cc9e1e38 100644 --- a/sphinx/templates/latex/longtable.tex.jinja +++ b/sphinx/templates/latex/longtable.tex.jinja @@ -22,15 +22,19 @@ <% if 'nocolorrows' in table.styles -%> \sphinxthistablewithnocolorrowsstyle <% endif -%> -\begin{longtable} -<%- if table.align in ('center', 'default') -%> - [c] -<%- elif table.align == 'left' -%> - [l] -<%- elif table.align == 'right' -%> - [r] -<%- endif -%> -<%= table.get_colspec() %> +\makeatletter +<%- if table.align in ('center', 'default') %> + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +<%- elif table.align == 'left' %> + \setlength\LTleft{\@totalleftmargin} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +<%- elif table.align == 'right' %> + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax} +<%- endif %> +\makeatother +\begin{longtable}<%= table.get_colspec() %> <%- if table.caption -%> \sphinxthelongtablecaptionisattop \caption{<%= ''.join(table.caption) %>\strut}<%= labels %>\\*[\sphinxlongtablecapskipadjust] diff --git a/tests/roots/test-latex-table/expects/longtable.tex b/tests/roots/test-latex-table/expects/longtable.tex index 754d10249..f74eb080c 100644 --- a/tests/roots/test-latex-table/expects/longtable.tex +++ b/tests/roots/test-latex-table/expects/longtable.tex @@ -4,7 +4,11 @@ \sphinxatlongtablestart \sphinxthistablewithglobalstyle \sphinxthistablewithborderlessstyle -\begin{longtable}[c]{ll} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{ll} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_align.tex b/tests/roots/test-latex-table/expects/longtable_having_align.tex index dcf8f83a1..8a3e8a955 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_align.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_align.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[r]{|l|l|} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax} +\makeatother +\begin{longtable}{|l|l|} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_caption.tex b/tests/roots/test-latex-table/expects/longtable_having_caption.tex index dd2a87fa6..603a3c108 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_caption.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_caption.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|l|l|} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|l|l|} \sphinxthelongtablecaptionisattop \caption{caption for longtable\strut}\label{\detokenize{longtable:id1}}\\*[\sphinxlongtablecapskipadjust] \sphinxtoprule diff --git a/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex index 8258612f5..479bdfafe 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|*{2}{\X{1}{2}|}} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|*{2}{\X{1}{2}|}} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex index 44114ce78..9ae535c19 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|*{3}{\X{1}{3}|}} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|*{3}{\X{1}{3}|}} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex b/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex index fc78914a9..029bc54c2 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_verbatim.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|*{2}{\X{1}{2}|}} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|*{2}{\X{1}{2}|}} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_having_widths.tex b/tests/roots/test-latex-table/expects/longtable_having_widths.tex index 5bf1507a7..706061cd8 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_widths.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_widths.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|\X{30}{100}|\X{70}{100}|} \noalign{\phantomsection\label{\detokenize{longtable:namedlongtable}}\label{\detokenize{longtable:mylongtable}}}% \sphinxtoprule \sphinxstyletheadfamily diff --git a/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex b/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex index bf9192009..f24ca827d 100644 --- a/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex +++ b/tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex @@ -3,7 +3,11 @@ \begin{savenotes} \sphinxatlongtablestart \sphinxthistablewithglobalstyle -\begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|\X{30}{100}|\X{70}{100}|} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex b/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex index 6383d9d56..57960d7e0 100644 --- a/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex +++ b/tests/roots/test-latex-table/expects/longtable_with_tabularcolumn.tex @@ -4,7 +4,11 @@ \sphinxatlongtablestart \sphinxthistablewithglobalstyle \sphinxthistablewithvlinesstyle -\begin{longtable}[c]{|c|c|} +\makeatletter + \setlength\LTleft{\@totalleftmargin plus1fill} + \setlength\LTright{\dimexpr\columnwidth-\@totalleftmargin-\linewidth\relax plus1fill} +\makeatother +\begin{longtable}{|c|c|} \sphinxtoprule \sphinxstyletheadfamily \sphinxAtStartPar diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 5dce900e2..8c6ecb96a 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1364,10 +1364,10 @@ def test_latex_table_with_booktabs_and_colorrows(app, status, warning): assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result # tabularcolumns - assert r'\begin{longtable}[c]{|c|c|}' in result + assert r'\begin{longtable}{|c|c|}' in result # class: standard assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result - assert r'\begin{longtable}[c]{ll}' in result + assert r'\begin{longtable}{ll}' in result assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index 7226a1167..1b56ef38e 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -538,7 +538,7 @@ def test_autosummary_latex_table_colspec(app, status, warning): result = (app.outdir / 'python.tex').read_text(encoding='utf8') print(status.getvalue()) print(warning.getvalue()) - assert r'\begin{longtable}[c]{\X{1}{2}\X{1}{2}}' in result + assert r'\begin{longtable}{\X{1}{2}\X{1}{2}}' in result assert r'p{0.5\linewidth}' not in result |
