@@ -1612,8 +1612,8 @@ print_latex_text(const printTableContent *cont, FILE *fout)
16121612 if (cancel_pressed )
16131613 return ;
16141614
1615- if (opt_border > 2 )
1616- opt_border = 2 ;
1615+ if (opt_border > 3 )
1616+ opt_border = 3 ;
16171617
16181618 if (cont -> opt -> start_table )
16191619 {
@@ -1628,20 +1628,20 @@ print_latex_text(const printTableContent *cont, FILE *fout)
16281628 /* begin environment and set alignments and borders */
16291629 fputs ("\\begin{tabular}{" , fout );
16301630
1631- if (opt_border = = 2 )
1631+ if (opt_border > = 2 )
16321632 fputs ("| " , fout );
16331633 for (i = 0 ; i < cont -> ncolumns ; i ++ )
16341634 {
16351635 fputc (* (cont -> aligns + i ), fout );
16361636 if (opt_border != 0 && i < cont -> ncolumns - 1 )
16371637 fputs (" | " , fout );
16381638 }
1639- if (opt_border = = 2 )
1639+ if (opt_border > = 2 )
16401640 fputs (" |" , fout );
16411641
16421642 fputs ("}\n" , fout );
16431643
1644- if (!opt_tuples_only && opt_border = = 2 )
1644+ if (!opt_tuples_only && opt_border > = 2 )
16451645 fputs ("\\hline\n" , fout );
16461646
16471647 /* print headers */
@@ -1668,6 +1668,8 @@ print_latex_text(const printTableContent *cont, FILE *fout)
16681668 if ((i + 1 ) % cont -> ncolumns == 0 )
16691669 {
16701670 fputs (" \\\\\n" , fout );
1671+ if (opt_border == 3 )
1672+ fputs ("\\hline\n" , fout );
16711673 if (cancel_pressed )
16721674 break ;
16731675 }
@@ -1679,7 +1681,7 @@ print_latex_text(const printTableContent *cont, FILE *fout)
16791681 {
16801682 printTableFooter * footers = footers_with_default (cont );
16811683
1682- if (opt_border = = 2 )
1684+ if (opt_border > = 2 )
16831685 fputs ("\\hline\n" , fout );
16841686
16851687 fputs ("\\end{tabular}\n\n\\noindent " , fout );
@@ -1701,6 +1703,162 @@ print_latex_text(const printTableContent *cont, FILE *fout)
17011703}
17021704
17031705
1706+ static void
1707+ print_latex_text_longtable (const printTableContent * cont , FILE * fout )
1708+ {
1709+ bool opt_tuples_only = cont -> opt -> tuples_only ;
1710+ unsigned short opt_border = cont -> opt -> border ;
1711+ unsigned int i ;
1712+ const char * opt_table_attr = cont -> opt -> tableAttr ;
1713+ const char * next_opt_table_attr_char = opt_table_attr ;
1714+ const char * last_opt_table_attr_char = NULL ;
1715+ const char * const * ptr ;
1716+
1717+ if (cancel_pressed )
1718+ return ;
1719+
1720+ if (opt_border > 3 )
1721+ opt_border = 3 ;
1722+
1723+ if (cont -> opt -> start_table )
1724+ {
1725+ /* begin environment and set alignments and borders */
1726+ fputs ("\\begin{longtable}{" , fout );
1727+
1728+ if (opt_border >= 2 )
1729+ fputs ("| " , fout );
1730+
1731+ for (i = 0 ; i < cont -> ncolumns ; i ++ )
1732+ {
1733+ /* longtable supports either a width (p) or an alignment (l/r) */
1734+ /* Are we left-justified and was a proportional width specified? */
1735+ if (* (cont -> aligns + i ) == 'l' && opt_table_attr )
1736+ {
1737+ #define LONGTABLE_WHITESPACE " \t\n"
1738+
1739+ /* advance over whitespace */
1740+ next_opt_table_attr_char += strspn (next_opt_table_attr_char ,
1741+ LONGTABLE_WHITESPACE );
1742+ /* We have a value? */
1743+ if (next_opt_table_attr_char [0 ] != '\0' )
1744+ {
1745+ fputs ("p{" , fout );
1746+ fwrite (next_opt_table_attr_char , strcspn (next_opt_table_attr_char ,
1747+ LONGTABLE_WHITESPACE ), 1 , fout );
1748+ last_opt_table_attr_char = next_opt_table_attr_char ;
1749+ next_opt_table_attr_char += strcspn (next_opt_table_attr_char ,
1750+ LONGTABLE_WHITESPACE );
1751+ fputs ("\\textwidth}" , fout );
1752+ }
1753+ /* use previous value */
1754+ else if (last_opt_table_attr_char != NULL )
1755+ {
1756+ fputs ("p{" , fout );
1757+ fwrite (last_opt_table_attr_char , strcspn (last_opt_table_attr_char ,
1758+ LONGTABLE_WHITESPACE ), 1 , fout );
1759+ fputs ("\\textwidth}" , fout );
1760+ }
1761+ else
1762+ fputc ('l' , fout );
1763+ }
1764+ else
1765+ fputc (* (cont -> aligns + i ), fout );
1766+
1767+ if (opt_border != 0 && i < cont -> ncolumns - 1 )
1768+ fputs (" | " , fout );
1769+ }
1770+
1771+ if (opt_border >= 2 )
1772+ fputs (" |" , fout );
1773+
1774+ fputs ("}\n" , fout );
1775+
1776+ /* print headers */
1777+ if (!opt_tuples_only )
1778+ {
1779+ /* firsthead */
1780+ if (opt_border >= 2 )
1781+ fputs ("\\toprule\n" , fout );
1782+ for (i = 0 , ptr = cont -> headers ; i < cont -> ncolumns ; i ++ , ptr ++ )
1783+ {
1784+ if (i != 0 )
1785+ fputs (" & " , fout );
1786+ fputs ("\\small\\textbf{\\textit{" , fout );
1787+ latex_escaped_print (* ptr , fout );
1788+ fputs ("}}" , fout );
1789+ }
1790+ fputs (" \\\\\n" , fout );
1791+ fputs ("\\midrule\n\\endfirsthead\n" , fout );
1792+
1793+ /* secondary heads */
1794+ if (opt_border >= 2 )
1795+ fputs ("\\toprule\n" , fout );
1796+ for (i = 0 , ptr = cont -> headers ; i < cont -> ncolumns ; i ++ , ptr ++ )
1797+ {
1798+ if (i != 0 )
1799+ fputs (" & " , fout );
1800+ fputs ("\\small\\textbf{\\textit{" , fout );
1801+ latex_escaped_print (* ptr , fout );
1802+ fputs ("}}" , fout );
1803+ }
1804+ fputs (" \\\\\n" , fout );
1805+ /* If the line under the row already appeared, don't do another */
1806+ if (opt_border != 3 )
1807+ fputs ("\\midrule\n" , fout );
1808+ fputs ("\\endhead\n" , fout );
1809+
1810+ /* table name, caption? */
1811+ if (!opt_tuples_only && cont -> title )
1812+ {
1813+ /* Don't output if we are printing a line under each row */
1814+ if (opt_border == 2 )
1815+ fputs ("\\bottomrule\n" , fout );
1816+ fputs ("\\caption[" , fout );
1817+ latex_escaped_print (cont -> title , fout );
1818+ fputs (" (Continued)]{" , fout );
1819+ latex_escaped_print (cont -> title , fout );
1820+ fputs ("}\n\\endfoot\n" , fout );
1821+ if (opt_border == 2 )
1822+ fputs ("\\bottomrule\n" , fout );
1823+ fputs ("\\caption[" , fout );
1824+ latex_escaped_print (cont -> title , fout );
1825+ fputs ("]{" , fout );
1826+ latex_escaped_print (cont -> title , fout );
1827+ fputs ("}\n\\endlastfoot\n" , fout );
1828+ }
1829+ /* output bottom table line? */
1830+ else if (opt_border >= 2 )
1831+ {
1832+ fputs ("\\bottomrule\n\\endfoot\n" , fout );
1833+ fputs ("\\bottomrule\n\\endlastfoot\n" , fout );
1834+ }
1835+ }
1836+ }
1837+
1838+ /* print cells */
1839+ for (i = 0 , ptr = cont -> cells ; * ptr ; i ++ , ptr ++ )
1840+ {
1841+ /* Add a line under each row? */
1842+ if (i != 0 && i % cont -> ncolumns != 0 )
1843+ fputs ("\n&\n" , fout );
1844+ fputs ("\\raggedright{" , fout );
1845+ latex_escaped_print (* ptr , fout );
1846+ fputc ('}' , fout );
1847+ if ((i + 1 ) % cont -> ncolumns == 0 )
1848+ {
1849+ fputs (" \\tabularnewline\n" , fout );
1850+ if (opt_border == 3 )
1851+ fputs (" \\hline\n" , fout );
1852+ }
1853+ if (cancel_pressed )
1854+ break ;
1855+ }
1856+
1857+ if (cont -> opt -> stop_table )
1858+ fputs ("\\end{longtable}\n" , fout );
1859+ }
1860+
1861+
17041862static void
17051863print_latex_vertical (const printTableContent * cont , FILE * fout )
17061864{
@@ -2394,6 +2552,12 @@ printTable(const printTableContent *cont, FILE *fout, FILE *flog)
23942552 else
23952553 print_latex_text (cont , fout );
23962554 break ;
2555+ case PRINT_LATEX_LONGTABLE :
2556+ if (cont -> opt -> expanded == 1 )
2557+ print_latex_vertical (cont , fout );
2558+ else
2559+ print_latex_text_longtable (cont , fout );
2560+ break ;
23972561 case PRINT_TROFF_MS :
23982562 if (cont -> opt -> expanded == 1 )
23992563 print_troff_ms_vertical (cont , fout );
0 commit comments