diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 5228938ef..7cdec13c9 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -339,7 +339,9 @@ class Table(object): return 'longtable' elif self.has_verbatim: return 'tabular' - elif self.has_problematic and not self.colspec: + elif self.colspec: + return 'tabulary' + elif self.has_problematic or (self.colwidths and 'colwidths-given' in self.classes): return 'tabular' else: return 'tabulary' diff --git a/tests/roots/test-latex-table/index.rst b/tests/roots/test-latex-table/index.rst index c559ccff8..ae461df2d 100644 --- a/tests/roots/test-latex-table/index.rst +++ b/tests/roots/test-latex-table/index.rst @@ -26,6 +26,19 @@ table having :widths: option cell3-1 cell3-2 ======= ======= +table with tabularcolumn +------------------------ + +.. tabularcolumns:: |c|c| + +======= ======= +header1 header2 +======= ======= +cell1-1 cell1-2 +cell2-1 cell2-2 +cell3-1 cell3-2 +======= ======= + table having caption -------------------- @@ -121,6 +134,22 @@ longtable having :widths: option cell3-1 cell3-2 ======= ======= +longtable with tabularcolumn +---------------------------- + +.. tabularcolumns:: |c|c| + +.. table:: + :class: longtable + + ======= ======= + header1 header2 + ======= ======= + cell1-1 cell1-2 + cell2-1 cell2-2 + cell3-1 cell3-2 + ======= ======= + longtable having caption ------------------------ diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 534270e45..4813fbbbc 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -841,15 +841,18 @@ def test_latex_table(app, status, warning): # table having :widths: option table = tables['table having :widths: option'] - assert ('\\noindent\\begin{tabulary}{\\linewidth}' - '{|\\X{30}{100}|\\X{70}{100}|}' in table) + assert ('\\noindent\\begin{tabular}{|\\X{30}{100}|\\X{70}{100}|}' in table) assert ('\\hline\n' '\\sphinxstylethead{\\relax \nheader1\n\\unskip}\\relax &' '\\sphinxstylethead{\\relax \nheader2\n\\unskip}\\relax' in table) assert ('\\hline\ncell1-1\n&\ncell1-2\n\\\\' in table) assert ('\\hline\ncell2-1\n&\ncell2-2\n\\\\' in table) assert ('\\hline\ncell3-1\n&\ncell3-2\n\\\\' in table) - assert ('\\hline\\end{tabulary}' in table) + assert ('\\hline\\end{tabular}' in table) + + # table with tabularcolumn + table = tables['table with tabularcolumn'] + assert ('\\noindent\\begin{tabulary}{\\linewidth}{|c|c|}' in table) # table having caption table = tables['table having caption'] @@ -902,6 +905,10 @@ def test_latex_table(app, status, warning): table = tables['longtable having :widths: option'] assert ('\\begin{longtable}{|\\X{30}{100}|\\X{70}{100}|}' in table) + # longtable with tabularcolumn + table = tables['longtable with tabularcolumn'] + assert ('\\begin{longtable}{|c|c|}' in table) + # longtable having caption table = tables['longtable having caption'] assert ('\\begin{longtable}{|l|l|}\n\\caption{caption for longtable}'