public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
From: BPJ <melroch-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: pandoc-discuss <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
Subject: Re: HTML to latex: Controlling table column width
Date: Fri, 30 Oct 2020 16:51:41 +0100	[thread overview]
Message-ID: <33efccd0-2bbf-a0af-4b26-3b3edb17e098@gmail.com> (raw)
In-Reply-To: <CADAJKhCi9r1XWV1J3cydLDy_vmkR_1yWZtimgZRTxCSdAO+rcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

On 2020-10-29 21:33, BPJ wrote:
> Den tors 29 okt. 2020 21:11'Oliver Demetz' via pandoc-discuss <
> pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> skrev:
> 
>> I could not find this CSS thing it in the docs,  can you point me to where
>> I find this?
>>
> It's just some CSS using rotate(-60), some negative padding and some extra
> padding at the top of the table to make room for the rotated text, and of
> course a similar filter to inject spans with classes.
> I have it on my work computer. I will post it as soon as I have started
> that computer tomorrow.
> 
> 

See the attached files.  Of course getting it to *really* work was 
harder than I remembered...

/bpj

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/33efccd0-2bbf-a0af-4b26-3b3edb17e098%40gmail.com.

[-- Attachment #2: test.html --]
[-- Type: text/html, Size: 2844 bytes --]

[-- Attachment #3: rotate-tab-heads.css --]
[-- Type: text/css, Size: 1750 bytes --]

table {
  border-collapse: collapse;
}

table th {
  font-weight: normal;
  border-bottom: 1px solid black;
}

div.rotate-table-headers {
  /************************************************************
    We need to set a padding above the table to make room
    for the rotated headers.

    Unfortunately the right amount of padding-top depends
    on the actual width of the widest column header text,
    so if possible you probably want to hard code a class/id
    or even a style attribute on the wrapping div and set the
    padding based on that.

    For the Pandoc filter solution I currently heuristically
    calculate a padding in ems from on the number of chars
    in the widest column header multiplied by a (fraction)
    factor and set a padding in a style attribute based on
    that. The factor can be modified by setting the metadata
    field `rotate_tab_heads_padding_factor` or the environment
    variable `PDC_ROTATE_TAB_HEADS_PADDING_FACTOR` to the
    desired factor. Not ideal but it works reasonably well
   ************************************************************/

  /* padding-top: 5em; */

  /* Uncomment to see box placement! *!
  /* border: 1px solid purple; */
}

div.rotate-table-headers table th span.rot {
  font-size: 0.85em;
  display: inline-block;
  white-space: nowrap;
  padding: 0;
  transform-origin: top left;
  transform: translateY(90%) rotate(-60deg);
  text-align: left !important;
  vertical-align: top;
  max-width: 3em;
  height: 1em;

  /* Uncomment to see box placement! *!
  /* border: 1px solid red; */
}

div.rotate-table-headers table th {
  padding: 0;
  max-height: 0.85em;
  text-align: left !important;

  /* Uncomment to see box placement! *!
  /* border: 1px solid blue; */
}


[-- Attachment #4: rotate-tab-heads.lua --]
[-- Type: text/x-lua, Size: 1677 bytes --]

local padding_factor = 0.35

local function tab_heads (tab)
  -- Convert the complex Table into a SimpleTable
  local simple = pandoc.utils.to_simple_table(tab)
  -- Check how many columns we got
  if #simple.widths < 7 then return nil end
  -- Reset column widths
  for i=1, #simple.widths do
    simple.widths[i] = 0.0
  end
  local widest_head = 0
  for _,head in ipairs(simple.headers) do
  -- Check that the header contains only one block
    if #head == 1 then
      -- Check that that block is a Para or Plain
      if 'Para' == head[1].tag or 'Plain' == head[1].tag then
        -- Get the width in UTF-8 chars
        -- TODO: ignore combining marks?
        local width = pandoc.text.len(pandoc.utils.stringify(head[1]))
        -- Update the max width as needed
        if width > widest_head then widest_head = width end
        -- Insert the span
        head[1].content = {pandoc.Span(head[1].content, {class = "rot"})}
      end
    end
  end
  tab = pandoc.utils.from_simple_table(simple)
  local style = ("padding-top: %.02fem;"):format(
    (padding_factor * widest_head)
  )
  return pandoc.Div(tab, {class="rotate-table-headers", style=style})
end

local function get_config (meta)
  local factor = meta.rotate_tab_heads_padding_factor
    or os.getenv'PDC_ROTATE_TAB_HEADS_PADDING_FACTOR'
  if nil == factor then return nil end
  if 'table' == type(factor) then
    factor = pandoc.utils.stringify(factor)
  end
  padding_factor = assert(
    tonumber(factor),
    "Expected meta.rotate_tab_heads_padding_factor \z
    or PDC_ROTATE_TAB_HEADS_PADDING_FACTOR to be number"
  )
  return nil
end

return {
  { Meta = get_config },
  { Table = tab_heads },
}


  parent reply	other threads:[~2020-10-30 15:51 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-28 12:01 'Oliver Demetz' via pandoc-discuss
     [not found] ` <848a5b18-0f4a-482e-ba35-d3af80f2a2aan-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-28 17:18   ` John MacFarlane
     [not found]     ` <m2imauuv4g.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2020-10-29  9:44       ` 'Oliver Demetz' via pandoc-discuss
     [not found]         ` <cecc57bd-2768-4124-962e-bb5f835cfd95n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-29 17:23           ` John MacFarlane
     [not found]             ` <m2imatrlne.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2020-10-29 18:31               ` John MacFarlane
     [not found]                 ` <m21rhgsx2p.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2020-10-29 18:54                   ` John MacFarlane
     [not found]                     ` <m2r1pgrhgx.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>
2020-11-02 16:16                       ` 'Oliver Demetz' via pandoc-discuss
     [not found]                         ` <e6e8f94d-0e94-4f6d-b03c-2325494177b8n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-11-02 16:37                           ` Albert Krewinkel
2020-10-29 19:24   ` BPJ
     [not found]     ` <CADAJKhCO9SFYvP9_Xg_NQe4NjHY8f-Xz6BJJy9CFY9ynvFzn-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-10-29 19:31       ` BPJ
     [not found]         ` <CADAJKhCb2bYQdYd4W_0b2703T8f96SHe4tYBVJDkofZ1Z1pr7Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-10-29 19:40           ` 'Oliver Demetz' via pandoc-discuss
     [not found]             ` <78d5fb66-4211-47b3-97b1-e8402b8e243dn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-29 19:56               ` BPJ
     [not found]                 ` <CADAJKhBWnr54SSbjoKHV8bqRkfkD7gKX2kkrLXUjT4Twfgy9Qw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-10-29 20:11                   ` 'Oliver Demetz' via pandoc-discuss
     [not found]                     ` <07d2b48b-e6b9-418a-b116-fdea9b92ae0bn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2020-10-29 20:33                       ` BPJ
     [not found]                         ` <CADAJKhCi9r1XWV1J3cydLDy_vmkR_1yWZtimgZRTxCSdAO+rcg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-10-30 15:51                           ` BPJ [this message]
2020-10-30 15:29                   ` Albert Krewinkel
     [not found]                     ` <87sg9vlokd.fsf-9EawChwDxG8hFhg+JK9F0w@public.gmane.org>
2020-10-30 20:04                       ` BPJ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33efccd0-2bbf-a0af-4b26-3b3edb17e098@gmail.com \
    --to=melroch-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).