Add styling rules in pandoc tables for odt/docx output (table borders) -


i'm generating odt/docx reports via markdown using knitr , pandoc , wondering how you'd go formating tables. i'm interested in adding rules (at least top, bottom , 1 below header, being able add arbitrary ones inside table nice too).

running following example pandoc documentation through pandoc (without special parameters) yields "plain" table without kind of rules/colours/guides (in either -t odt or -t docx).

+---------------+---------------+--------------------+ | fruit         | price         | advantages         | +===============+===============+====================+ | bananas       | $1.34         | - built-in wrapper | |               |               | - bright color     | +---------------+---------------+--------------------+ | oranges       | $2.10         | - cures scurvy     | |               |               | - tasty            | +---------------+---------------+--------------------+ 

i've looked through "styles" possibility of specifying table formating in reference .docx/.odt found nothing obvious beyond "table header" , "table contents" styles, both of seem concern formatting of text within table.

being rather unfamiliar wysiwyg-style document processors i'm lost how continue.

here's how searched how this:

the way add table in docx use <w:tbl> tag. searched in github repository, , found in file (called writers/docx.hs, it's not big surprise)

blocktoopenxml opts (table caption aligns widths headers rows) =   let captionstr = stringify caption   caption' <- if null caption                  return []                  else withparaprop (pstyle "tablecaption")                       $ blocktoopenxml opts (para caption)   let alignmentfor al = mknode "w:jc" [("w:val",alignmenttostring al)] ()   let celltoopenxml (al, cell) = withparaprop (alignmentfor al)                                     $ blockstoopenxml opts cell   headers' <- mapm celltoopenxml $ zip aligns headers   rows' <- mapm (\cells -> mapm celltoopenxml $ zip aligns cells)            $ rows   let borderprops = mknode "w:tcpr" []                     [ mknode "w:tcborders" []                       $ mknode "w:bottom" [("w:val","single")] ()                     , mknode "w:valign" [("w:val","bottom")] () ]   let mkcell border contents = mknode "w:tc" []                             $ [ borderprops | border ] ++                             if null contents                                [mknode "w:p" [] ()]                                else contents   let mkrow border cells = mknode "w:tr" [] $ map (mkcell border) cells   let textwidth = 7920  -- 5.5 in in twips, 1/20 pt   let mkgridcol w = mknode "w:gridcol"                        [("w:w", show $ (floor (textwidth * w) :: integer))] ()   return $     [ mknode "w:tbl" []       ( mknode "w:tblpr" []         ( [ mknode "w:tblstyle" [("w:val","tablenormal")] () ] ++           [ mknode "w:tblcaption" [("w:val", captionstr)] ()           | not (null caption) ] )       : mknode "w:tblgrid" []         (if (==0) widths             []             else map mkgridcol widths)       : [ mkrow true headers' | not (all null headers) ] ++       map (mkrow false) rows'       )     ] ++ caption' 

i'm not familiar @ haskell, can see border-style hardcoded, since there no variable in it:

let borderprops = mknode "w:tcpr" []                     [ mknode "w:tcborders" []                       $ mknode "w:bottom" [("w:val","single")] ()                     , mknode "w:valign" [("w:val","bottom")] () ] 

what mean ?

that means can't change style of docx tables current version of pandoc. howewer, there's way own style.

how own style ?

  1. create docx document style want on table (by creating table)
  2. change extension of file , unzip it
  3. open word/document.xml , search <w:tbl>
  4. try find out how style translates in xml , change borderprops according see.

here's test border-style created: custom border style

and here corresponding xml:

<w:tblborders>   <w:top w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/>   <w:left w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/>   <w:bottom w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/>   <w:right w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/>   <w:insideh w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/>   <w:insidev w:val="dotted" w:sz="18" w:space="0" w:color="c0504d" w:themecolor="accent2"/> </w:tblborders> 

what odt ?

i didn't have @ yet, ask if don't find using similar method.

hope helps , don't hesitate ask more


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -