@@ -1612,8 +1612,8 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1612
1612
if (cancel_pressed )
1613
1613
return ;
1614
1614
1615
- if (opt_border > 2 )
1616
- opt_border = 2 ;
1615
+ if (opt_border > 3 )
1616
+ opt_border = 3 ;
1617
1617
1618
1618
if (cont -> opt -> start_table )
1619
1619
{
@@ -1628,20 +1628,20 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1628
1628
/* begin environment and set alignments and borders */
1629
1629
fputs ("\\begin{tabular}{" , fout );
1630
1630
1631
- if (opt_border = = 2 )
1631
+ if (opt_border > = 2 )
1632
1632
fputs ("| " , fout );
1633
1633
for (i = 0 ; i < cont -> ncolumns ; i ++ )
1634
1634
{
1635
1635
fputc (* (cont -> aligns + i ), fout );
1636
1636
if (opt_border != 0 && i < cont -> ncolumns - 1 )
1637
1637
fputs (" | " , fout );
1638
1638
}
1639
- if (opt_border = = 2 )
1639
+ if (opt_border > = 2 )
1640
1640
fputs (" |" , fout );
1641
1641
1642
1642
fputs ("}\n" , fout );
1643
1643
1644
- if (!opt_tuples_only && opt_border = = 2 )
1644
+ if (!opt_tuples_only && opt_border > = 2 )
1645
1645
fputs ("\\hline\n" , fout );
1646
1646
1647
1647
/* print headers */
@@ -1668,6 +1668,8 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1668
1668
if ((i + 1 ) % cont -> ncolumns == 0 )
1669
1669
{
1670
1670
fputs (" \\\\\n" , fout );
1671
+ if (opt_border == 3 )
1672
+ fputs ("\\hline\n" , fout );
1671
1673
if (cancel_pressed )
1672
1674
break ;
1673
1675
}
@@ -1679,7 +1681,7 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1679
1681
{
1680
1682
printTableFooter * footers = footers_with_default (cont );
1681
1683
1682
- if (opt_border = = 2 )
1684
+ if (opt_border > = 2 )
1683
1685
fputs ("\\hline\n" , fout );
1684
1686
1685
1687
fputs ("\\end{tabular}\n\n\\noindent " , fout );
@@ -1701,6 +1703,162 @@ print_latex_text(const printTableContent *cont, FILE *fout)
1701
1703
}
1702
1704
1703
1705
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
+
1704
1862
static void
1705
1863
print_latex_vertical (const printTableContent * cont , FILE * fout )
1706
1864
{
@@ -2394,6 +2552,12 @@ printTable(const printTableContent *cont, FILE *fout, FILE *flog)
2394
2552
else
2395
2553
print_latex_text (cont , fout );
2396
2554
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 ;
2397
2561
case PRINT_TROFF_MS :
2398
2562
if (cont -> opt -> expanded == 1 )
2399
2563
print_troff_ms_vertical (cont , fout );
0 commit comments