17

How do you left align an entire table in Markdown/Pandoc? I know about different ways of specifying tables and how alignment of columns are done, but I cannot find a way to shift the table from center aligned to left aligned (have even tryed embedding <div style="float: left>..</div> which didn't work). Do I have to switch to LaTeX to do this? I will export to pdf later on, if that makes a difference.

fileunderwater
  • 1,125
  • 2
  • 12
  • 31
  • I'm voting to close this question as off-topic because it is better suited for http://tex.stackexchange.com/. – Dave Jarvis Dec 05 '15 at 03:18
  • 1
    @DaveJarvis Questions can be on-topic at several SE-sites though. And this question is dealing just as much with markdown as latex. And what about the other 4,432 questions tagged 'latex' at SO? – fileunderwater Dec 05 '15 at 09:59
  • Given that a solution was found at TeX SE... Also, SO is about programming. Asking for help with a custom Haskell filter for Pandoc that changes the output document would be programming. Asking for help with how to *use* Pandoc or customise the LaTeX output it generates is more about TeX and software usage than programming. (And I don't have time to scrutinize the other 4k questions, only the ones I find serendipitously.) – Dave Jarvis Dec 05 '15 at 21:00
  • 1
    @DaveJarvis The question is on-topic because markdown can also be considered programming. – ABCD Nov 16 '17 at 00:48

3 Answers3

6

I now found a solution to this problem at tex.stackexchange.com. Apparently pandoc inserts \centering for every float in the document. This can be cancelled by inserting \let\centering\relax in a custom preample to pandoc (as pandoc argument -H custompreample.tex). The link also describes more detailed ways to for example define different floats for tables and figures.

Community
  • 1
  • 1
fileunderwater
  • 1,125
  • 2
  • 12
  • 31
  • While this will solve your problem, it will prevent *any* element from being centred. This many not bother you, but it might be a problem for others wanting to use this solution. – Richard Smith Sep 11 '16 at 22:43
  • 6
    A better solution is to create a custom preamble containing: `\usepackage{longtable}\setlength{\LTleft}{2em}`. – Richard Smith Sep 11 '16 at 22:56
2

I was not able to get the solutions here to work--in LaTeX. I created a new longtable environment to make tables the way I wanted them. That was easier in the end. Here's an example Rmd file.

---
title: "Custom table"
header-includes:
  - \usepackage{longtable,booktabs}
output: pdf_document
---

\newenvironment{mylong}
    {\begin{longtable}[l]{p{.25in}p{3in}p{3in}}Line & Statements  & Reasons\\
    \toprule\addlinespace }
    { \addlinespace\bottomrule\end{longtable} }

\begin{mylong} 
1& $a+b=a+d$    & Given P10, if $b=d$, then 1 is true\\
2& $a+b=c$ & Given\\
3& $a+d=c$ & Given P9, if 1 and 2 are true, then 3 is true. QED\\
\end{mylong}
Eli Holmes
  • 656
  • 7
  • 10
2

I've found this solution here.

a simple \usepackage in header-includes: that looks doing the job itself...

- \usepackage[margins=raggedright]{floatrow} 

I hope it won't have side effects. Currently, on my pandoc generated pdfs, none, but I don't know its boundaries.

  • it has at least one limit: it applies upon every table of your pdf, and not a single one, if it's what you were looking for.
Marc Le Bihan
  • 2,308
  • 2
  • 23
  • 41