How to left align a whole table in markdown (pandoc)?
Asked Answered
K

3

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.

Kirtle answered 10/1, 2014 at 11:37 Comment(4)
I'm voting to close this question as off-topic because it is better suited for tex.stackexchange.com.Lindsy
@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?Kirtle
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.)Lindsy
@DaveJarvis The question is on-topic because markdown can also be considered programming.Windle
K
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.

Kirtle answered 10/1, 2014 at 12:17 Comment(2)
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.Thoroughfare
A better solution is to create a custom preamble containing: \usepackage{longtable}\setlength{\LTleft}{2em}.Thoroughfare
B
3

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.
Banderole answered 20/8, 2022 at 4:40 Comment(0)
D
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}
Delinda answered 11/12, 2015 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.