Announcement

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

  • Border styles in collect export to html

    I have been having fun with the new system for producing publication-quality tables. I noticed, however, that exporting a table to -html- produces rather thick borders, while exporting the same table to -docx- or -pdf- (directly or via -tex-) produces thin borders. Here is a simple example

    Code:
    webuse nhanes2l, clear    
    table hlthstat region
    collect export table1.pdf, replace
    with screen grabs for html and pdf via LaTeX.

    Click image for larger version

Name:	table1-html.png
Views:	1
Size:	6.1 KB
ID:	1612969

    Click image for larger version

Name:	table1-pdf.png
Views:	1
Size:	21.9 KB
ID:	1612970


    I believe this happens because Stata sets borders in html using -top-border-style:solid-, which makes the -width- of the border default to -medium-, or about 3 pixels. I wonder if there is any way to change the default border width.

    I can, of course, change the border width for specific cells, but this is not easy. I can remove the vertical border by setting -border(right, pattern(nil))- for all cells, as shown in the manual. I can edit the top border by targeting -border-block-, and the bottom border by targeting level -.m- of -hlthstat-, but I can't figure out how to edit the middle one.

    I also think it would be nice to make these edits without reference to specific variables and categories, so the styles can be saved and reused in different tables. Perhaps a way to target the table header and body and the first and last rows of these, as done in css.

  • #2
    I think I have answered my own question, at least in large part. Here is the code that worked, which I am posting in case it helps others. The solution was to target the -border_block-, which is explained briefly in [TABLE p, 38] and divides the table into the row-headers, the column-headers, the items, and the corner in the top left; all as blocks rather than cells.

    Code:
    webuse nhanes2l
    table hlthstat region
    collect style cell border_block[corner row-header], border(right, width(0.5pt))
    collect style cell border_block[corner column-header], border(top, width(0.5pt))
    collect style cell border_block[row-header item], border(top bottom, width(0.5pt))
    collect export table1.html, replace
    view browse table1.html
    Here is the html screen capture:



    I was also interested in saving these border styles for use in other tables. I found no way to change the default border styles, short of editing -styles-default_borders.stjson- directly. It is possible to create a new table style following the discussion in [TABLES, pp. 219ff], and even set it as the default style to be used by -table-, but this has to be done separately for other styles, including the default style used by -collect-. An alternative is to write a Stata command to wrap the border edits.

    Comment


    • #3
      German,
      Thanks for posting this code. It added to the information I was able to find the documentation.
      Here are a couple of additional examples for those, like us, who are needing to control their border style.
      The first one shows how to specify each piece of the border and colors it garishly.
      The second one shows how to remove the border, which might sound like it is obvious once you know how to change the color, but there are a couple of twists.
      May

      Code:
      clear
      webuse nhanes2l
      table (hlthstat) (region)
      collect style cell border_block[corner], border(right, width(5pt) color(red))
      collect style cell border_block[corner], border(top, width(5pt) color(orange))
      collect style cell border_block[corner], border(bottom, width(5pt) color(yellow))
      
      collect style cell border_block[row-header], border(right, width(5pt) color(lime))
      collect style cell border_block[row-header], border(bottom, width(5pt) color(cyan))
      
      collect style cell border_block[column-header], border(top, width(5pt) color(magenta))
      collect style cell border_block[column-header], border(bottom, width(5pt) color(blue))
      
      collect style cell border_block[item], border(bottom, width(5pt) color(chocolate))
      
      collect export table1.html, replace
      view browse table1.html
      Code:
      clear
      webuse nhanes2l
      table (hlthstat) (region)
      collect style cell border_block[corner], border(right, pattern(nil))
      collect style cell border_block[corner], border(top, pattern(nil))
      
      collect style cell border_block[corner], border(bottom, pattern(nil)) /* doesn't work */
      collect style cell border_block[row-header], border(top, pattern(nil)) /* this works */
      
      collect style cell border_block[row-header], border(right, pattern(nil))
      collect style cell border_block[row-header], border(bottom, pattern(nil))
      
      collect style cell border_block[column-header], border(top, pattern(nil))
      
      collect style cell border_block[column-header], border(bottom, pattern(nil)) /* doesn't work */
      collect style cell border_block[item], border(top, pattern(nil)) /* this works */
      
      collect style cell border_block[item], border(bottom, pattern(nil))
      
      collect export table1.html, replace
      view browse table1.html

      Comment

      Working...
      X