From c6a55f8e9f189d2cda279ff2ee5f17e516490942 Mon Sep 17 00:00:00 2001
From: Jesse Rosenthal <jrosenthal@jhu.edu>
Date: Mon, 15 Jan 2018 15:51:58 -0500
Subject: [PATCH] Powerpoint writer: Improve table placement.

---
 src/Text/Pandoc/Writers/Powerpoint/Output.hs | 14 +++++---------
 1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/Text/Pandoc/Writers/Powerpoint/Output.hs b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
index 68f3991ea..95dccb655 100644
--- a/src/Text/Pandoc/Writers/Powerpoint/Output.hs
+++ b/src/Text/Pandoc/Writers/Powerpoint/Output.hs
@@ -842,9 +842,6 @@ shapesToElements :: PandocMonad m => Element -> [Shape] -> P m [Element]
 shapesToElements layout shps = do
  concat <$> mapM (shapeToElements layout) shps
 
-hardcodedTableMargin :: Integer
-hardcodedTableMargin = 36
-
 graphicFrameToElements :: PandocMonad m => Element -> [Graphic] -> [ParaElem] -> P m [Element]
 graphicFrameToElements layout tbls caption = do
   -- get the sizing
@@ -857,7 +854,7 @@ graphicFrameToElements layout tbls caption = do
 
   let cy = if (not $ null caption) then cytmp - captionHeight else cytmp
 
-  elements <- mapM graphicToElement tbls
+  elements <- mapM (graphicToElement cx) tbls
   let graphicFrameElts =
         mknode "p:graphicFrame" [] $
         [ mknode "p:nvGraphicFramePr" [] $
@@ -878,20 +875,19 @@ graphicFrameToElements layout tbls caption = do
             return [graphicFrameElts, capElt]
     else return [graphicFrameElts]
 
-graphicToElement :: PandocMonad m => Graphic -> P m Element
-graphicToElement (Tbl tblPr hdrCells rows) = do
-  (pageWidth, _) <- asks envPresentationSize
+graphicToElement :: PandocMonad m => Integer -> Graphic -> P m Element
+graphicToElement tableWidth (Tbl tblPr hdrCells rows) = do
   let colWidths = if null hdrCells
                   then case rows of
                          r : _ | not (null r) -> replicate (length r) $
-                                                (pageWidth - (2 * hardcodedTableMargin))`div` (toInteger $ length r)
+                                                (tableWidth `div` (toInteger $ length r))
                          -- satisfy the compiler. This is the same as
                          -- saying that rows is empty, but the compiler
                          -- won't understand that `[]` exhausts the
                          -- alternatives.
                          _ -> []
                   else replicate (length hdrCells) $
-                       (pageWidth - (2 * hardcodedTableMargin)) `div` (toInteger $ length hdrCells)
+                       (tableWidth `div` (toInteger $ length hdrCells))
 
   let cellToOpenXML paras =
         do elements <- mapM paragraphToElement paras