How to left align a whole table in markdown (pando

2019-03-20 13:33发布

问题:

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.

回答1:

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.



回答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}