antonio
antonio

Reputation: 11140

Right align (an address) in Pandoc

Right alignment comes handy for letter addresses. Unfortunately, according to the author John MacFarlane:

The pandoc document model does not allow for alignment other than in tables, so the alignment information is simply ignored.

We can resort to raw LaTeX.

Upon trial and error (and googling) I found that this TeX syntax works as intended:

\rightline{Address 1}
\rightline{Address 2}
\rightline{etc}

Also the LaTeX equivalent does:

\begin{flushright}

Address 1\\
Address 2\\
etc

\end{flushright}

The less invasive syntax, based on the LaTeX command raggedleft, unfortunately does not work:

{\raggedleft
Address 1\\
Address 2\\
etc\\
}

This is because braces are passed verbatim (\{, \}) and not as raw LaTeX.

With reference to centre alignment, I found a user claiming that markdown supports this native (beautiful) syntax:

-> This is center align <-

but I didn't find an editor/converter supporting it.

Indeed my working examples are all against the John Gruber markdown philosophy:

A Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions.

Can you find a better way?

Particularly is it possible to simply write a Pandoc template to redefine the alignment of a header, say: ###### Right aligned?

Upvotes: 8

Views: 6991

Answers (2)

Jon49
Jon49

Reputation: 4606

For those that are looking for a similar question here's how to left align/right align on the same line:

**Some bolded text** **\hfill some right aligned on same line bolded text**

You'll have to imagine the result since I'm not sure how to recreate it on SO.

Upvotes: 13

John MacFarlane
John MacFarlane

Reputation: 8947

The best way to handle this is to put the address in a YAML metadata block (supported by pandoc 1.12+), and do the alignment in a custom template. Then your source document will be clean, without raw LaTeX, and you can modify templates to get the desired look in any output format.

Source document could look like this:

---
address:
  | 23 Main St.
  | Somewhere, MT 23434
...

Dear so and so,

Then in your LaTeX template you'd have something like:

\begin{flushright}
$address$
\end{flushright}

If you're writing a letter, though, it would probably be better to write a template using the LaTeX letter class.

Upvotes: 4

Related Questions