How to make horizontal layout of pandoc markdown tables?

Code

pandoc                              \
     data.tex                       \
    -f markdown                     \
    -t html                         \
                                    \
| grep -E '(^<|^$|^ *$)'            \
                                    \
| grep -v '^<p'                     \
                                    \
| perl -pe 's#(?<!\\)%.*</#</#'     \
                                    \
| pandoc                            \
    -f html                         \
    -o vertical_output.pdf          \
    --latex-engine=xelatex

which gives tables on vertical layout as output, see the picture below.

Example case where horizontal table is needed

The content of the file data.tex is the following data.

Data.tex:

--------------------------------------------------------------------------------------------------------------------------------------------
Name            Description     Location        Examples            Start            Peak            Duration        Appearance
--------------- --------------- --------------  ------------------- ---------------- --------------  ---------------  -------------------
Prandial        short-acting    belly,          Lispro (Humalog),   5-10 min before  30-60 minutes   2-4 hours       Transparent
                analogs         abdomen         Aspart (Novorapid), meal
                = chemically                    Glulisine (Apidra)
                sythesized;


Regular/short   human insulin   addomen         Humulin R           30 min before    60 minutes      6-8 hours,       Transparent
                not analog                                          meal                             hypoglycemia
                                                                    not flexible                     risk 
-------------------------------------------------------------------------------------------------------------------------------------------

Table: Diabetic drugs parndial and basal. Location, start, peak, duration and appearance. 

giving by running the above code to the data

enter image description here

Comments

Too much space around sparse tables

One document has many types of tables. The current accepted answer works well if tables are rather full, but badly with sparse tables. Using the parameter of the accepted answer -V geometry:"paperwidth=22in, paperheight=210mm, margin=2cm", we get:

enter image description here

where the second table is extended too much; I would like to have it narrower; but not sure if this is possible dynamically in Pandoc.


How can you have a horizontal layout of pandocing?

Upvotes: 3

Views: 2862

Answers (1)

Kurt Pfeifle
Kurt Pfeifle

Reputation: 90345

Whenever you use Pandoc to produce PDF output, you can control the page size of the file with an addition to the command line. For example, generate a page with a width of 22 inches and a height of 210 Millimeters, while keeping each margin at 2 Centimeters, use this Pandoc parameter:

-V geometry:"paperwidth=22in, paperheight=210mm, margin=2cm"

I hope this example makes clear to you how you can influence the output paper size in different other ways.

However, I do not know if it answers your question. Your question is not very clear to me, I must admit.

My answer however may help other people when searching for "horizontal layout pandoc markdown".

Full commands to try

First, 12 inches width:

pandoc                              \
     data.tex                       \
    -f markdown                     \
    -t html                         \
                                    \
| grep -E '(^<|^$|^ *$)'            \
                                    \
| grep -v '^<p'                     \
                                    \
| perl -pe 's#(?<!\\)%.*</#</#'     \
                                    \
| pandoc                            \
    -f html                         \
    -o vertical_output1.pdf         \
    --latex-engine=xelatex          \
    -V geometry:"paperwidth=12in, paperheight=80mm, margin=0.5cm"

Second, 14 inches width:

pandoc                              \
     data.tex                       \
    -f markdown                     \
    -t html                         \
                                    \
| grep -E '(^<|^$|^ *$)'            \
                                    \
| grep -v '^<p'                     \
                                    \
| perl -pe 's#(?<!\\)%.*</#</#'     \
                                    \
| pandoc                            \
    -f html                         \
    -o vertical_output1.pdf         \
    --latex-engine=xelatex          \
    -V geometry:"paperwidth=14in, paperheight=80mm, margin=0.5cm"

Outputs (as PNG screenshots from the PDFs to make them visible here):

Upvotes: 3

Related Questions