Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • putpdf: how to minimize space between table rows?

    I am testing the creation of documents with putpdf. Below are commands that demonstrate a problem I encountered: I don't know how to minimize the space between rows in a table.
    Code:
    sysuse auto
    putpdf clear
    putpdf begin, font("Arial",10)
    putpdf paragraph, spacing(line, 1 pt)
    putpdf text ("Table 1"), bold
    putpdf table tab1 = data(make price mpg rep78) in 1/10, varnames
    forval i = 1/11 {
      putpdf table tab1(`i',.), font("Arial",8) margin(top, 1 twip) margin(bottom, 1 twip) valign(center)
    }
    forval i = 3/10 {
      putpdf table tab1(`i',.), border(top,nil) border(bottom,nil)
    }
    putpdf table tab1(1,.), bold
    putpdf save tabletest.pdf, replace
    The resulting table, shown below, has a lot of space between individual rows although I set the top and bottom margins for all rows to 1 twip. How can I reduce the space between rows so that the table is more compact?
    Click image for larger version

Name:	table.png
Views:	1
Size:	16.2 KB
ID:	1405842

    A related question: Is it possible to set the font, margins and other options for all rows in a table without referring to each row individually, as I did with the forval i = 1/11 loop?

  • #2
    Stata tech support confirmed that there is a bug in the putpdf code. When margins are set to less than 2 pt, the margins are ignored. In addition, the cell font size has no effect on the cell height if the cell font size is less than the document font size. This will be fixed in a future update.

    As a workaround, the document font can be set to a smaller size - with putpdf begin, font() - to reduce the height of table rows, as shown in the example below.
    Code:
    sysuse auto
    putpdf clear
    putpdf begin, font("Arial",6)
    putpdf paragraph, spacing(line, 1 pt)
    putpdf text ("Table 1"), bold font("Arial",10)
    putpdf table tab1 = data(make price mpg rep78) in 1/10, varnames
    forval i = 1/11 {
      putpdf table tab1(`i',.), font("Arial",8) margin(top, 1 twip) margin(bottom, 1 twip) valign(center)
    }
    forval i = 3/10 {
      putpdf table tab1(`i',.), border(top,nil) border(bottom,nil)
    }
    putpdf table tab1(1,.), bold
    putpdf save tabletest2.pdf, replace
    Click image for larger version

Name:	table2.png
Views:	1
Size:	12.0 KB
ID:	1408802


    Tech support also confirmed that there is currently no option to set the font, margins and other options for all rows in a table. This means that these options have to be set by referring to all rows, columns or cells individually, as in the forval loops above.

    Comment


    • #3
      The problems described above have been partly fixed in Stata 15.1. Margins can now be set to less than 2 pt. It is also possible to format several cells at once so that the forval loops are no longer necessary.
      Code:
      sysuse auto
      putpdf clear
      putpdf begin, font("Arial",10)
      putpdf paragraph, spacing(line, 1 pt)
      putpdf text ("Table 1"), bold
      putpdf table tab1 = data(make price mpg rep78) in 1/10, varnames
      putpdf table tab1(1/11,.), font("Arial",8) margin(top, 1 twip) margin(bottom, 1 twip) valign(center)
      putpdf table tab1(3/10,.), border(top,nil) border(bottom,nil)
      putpdf table tab1(1,.), bold
      putpdf save tabletest3.pdf, replace
      Click image for larger version

Name:	table3.png
Views:	1
Size:	11.9 KB
ID:	1417390

      One problem remains: the table looks identical with any margin between 0 and 19 twips, as shown in the image above. I will contact Stata tech support about this.

      Comment


      • #4
        Stata tech support explained that margins specified in twips (one twentieth of a point) are converted to points with a floor() function. This means that 0-19 twip becomes 0 pt, 20-39 twip becomes 1 pt, 40-59 twip becomes 2 pt, and so on. Because of this conversion, the table in post #3 looks the same with any margin between 0 and 19 twips and you would get the same result by specifying 0 pt margins.

        I also learned that it is apparently not possible to eliminate all space between rows in a table because Stata adds a 1 pt space to the top and bottom of all cells to avoid overlapping lines. The rows in the table in post #3 can therefore not be brought closer together.

        Comment

        Working...
        X