Make org-mode table caption appear below table when exported to LaTeX - emacs

I'm producing a document using org-mode which has quite a few tables in it, constructed using the built in table functionality. I've added captions to the tables, but when I export them to LaTeX, rather than the caption appearing below the table, it appears above it. In the manual section on tables and the latex export documentation, there is no mention of any method of changing this, other than fiddling with the LaTeX code manually. As an illustration, the following code snippets show what is generated by the export on an example table with a caption.
#+CAPTION: Results using two methods with different parameter settings.
#+LABEL: tbl:rescomp
| Parameter | Result 1 | Result 2 |
|-----------+----------+----------|
| 0.5 | 0.1 | 0.8 |
| 1 | 0.8 | 0.1 |
Exported:
\begin{table}[htb]
\caption{Results using two methods with different parameter settings.}
\label{tbl:rescomp}
\begin{center}
\begin{tabular}{rrr}
Parameter & Result 1 & Result 2 \\
\hline
0.5 & 0.1 & 0.8 \\
1 & 0.8 & 0.1 \\
\end{tabular}
\end{center}
\end{table}
The problem could be fixed very simply. The caption appears above the table in the document because it is above the table in the code. Moving the caption definition below the tabular section fixes the issue:
\begin{table}[htb]
\begin{center}
\begin{tabular}{rrr}
Parameter & Result 1 & Result 2 \\
\hline
0.5 & 0.1 & 0.8 \\
1 & 0.8 & 0.1 \\
\end{tabular}
\end{center}
\caption{Results using two methods with different parameter settings.}
\label{tbl:rescomp}
\end{table}
Placing the caption definition below the table in the org file is not possible, as it defines the caption for the next table, as described in the manual. Is there any way that I can get org-mode to export the caption below the table produced?

Just updating the answer for Org-mode version 8.3.2 because setting org-export-latex-table-caption-above to nil does nothing now.
I added the next line to my .emacs or init.el file:
(setq org-latex-caption-above nil)
Just as a side note, that variable contains the value (table) by default, which is the one that we are overriding to nil.

In the link posted by N.N., a patch to implement functionality to allow captions to be placed above or below the float was applied. Looking at the org-mode code on github, the default behaviour of Emacs 24.1 is to place captions above the table. To place captions below tables instead, set the org-export-latex-table-caption-above variable to nil:
M-x customize-variable RET org-export-latex-table-caption-above RET nil
or
M-x set-variable RET org-export-latex-table-caption-above RET nil

Related

Emacs, AUCTeX and indentation of custom commands

I'm preparing a document that contains colored tables (using colortbl) and to correct the thin white lines that appear in those tables I'm using a custom new line macro to compensate for that. However, AUCTeX does not recognize the new macro and tries to indent the table in a strange way.
\begin{table}[h]
\centering\sffamily
\begin{tabular}{lcc}
\rowcolor{row1} \textbf{Nominative} & \emph{Wer?} & Who? \mynewline
\rowcolor{row2}\textbf{Accusative} & \emph{Wen?} & Who(m)? \\
\rowcolor{row1} \textbf{Dative} & \emph{Wem?} & To who(m)? \\
\rowcolor{row2} \textbf{Genitive} & \emph{Wessen?} & Whose? \mynewline
\end{tabular}
\end{table}
How can I make AUCTeX understand that \mynewline plays the same role as \\?
In many cases, AUCTeX should be able to learn about your own commands automatically if you set TeX-parse-self and TeX-auto-save to t. See https://www.gnu.org/software/auctex/manual/auctex/Parsing-Files.html#Parsing-Files
If that is not sufficient, you can tell AUCTeX about your own macros and environment using a style file. See https://www.gnu.org/software/auctex/manual/auctex/Style-Files.html#Style-Files for more on this. It boils down to using the function TeX-add-symbols correctly.
Please note that it's been a few years since I last did this.
AUCTeX ships with a style file for longtable which seems to contain exactly what you need. See http://git.savannah.gnu.org/cgit/auctex.git/tree/style/longtable.el#n92
(TeX-add-symbols
;; Commands to end table rows
'("endhead" 0)
'("endfirsthead" 0)
'("endfoot" 0)
'("endlastfoot" 0)
;; Caption commands
'("caption*" 1))

Is it possible to create and preview a table using Visual Studio Code Markdown?

I am using Visual Studio Code to write some notes using its Markdown support. I would like to add some tables, but I can't find a way to do it. It seems that Visual Studio Code implements CommonMark which does not include tables in the specification.
I know that GitHub flavoured Markdown has a table extension which provides this feature and there are a couple of table formatter Visual Studio Code extensions (here and here), but they just layout the text nicely. I would like to a table to show up in the preview pane.
Any suggestions for how to achieve some tables in Visual Studio Code Markdown?
You can now do something like this:
| Letter | Digit | Character |
| :----: | :---: | :-------: |
| a | 4 | $ |
| | 365 | ( |
| b | | ^ |
"Empty" cells must have at least one space in them. This will display in vscode's markdown preview as:
The original Markdown rules state:
For any markup that is not covered by Markdown's syntax, you simply
use HTML itself. There's no need to preface it or delimit it to
indicate that you're switching from Markdown to HTML; you just use the
tags.
The only restrictions are that block-level HTML elements -- e.g.
<div>, <table>, <pre>, <p>, etc. -- must be separated from
surrounding content by blank lines, and the start and end tags of the
block should not be indented with tabs or spaces. Markdown is smart
enough not to add extra (unwanted) <p> tags around HTML block-level
tags.
For example, to add an HTML table to a Markdown article:
This is a regular paragraph.
<table>
<tr>
<td>Foo</td>
</tr>
</table>
This is another regular paragraph.
Note that Markdown formatting syntax is not processed within
block-level HTML tags. E.g., you can't use Markdown-style *emphasis*
inside an HTML block.

How can I stop org mode from moving my figures to the last page?

I'm currently trying to write up my thesis in emacs org-mode, and have run into some problems with file inclusions.
When I include figures with:
#+NAME: fig:banana
#+CAPTION: this is a figure caption
[[/path/to/image.png]]
(or using a pdf) it works fine. But when I insert another image, it is somehow moved to the end of the file instead of being inserted where it is called.
My pdf-export process (in my ~/.emacs file) looks like this:
(setq org-latex-pdf-process
'("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f"))
Any ideas on how to fix this?
A friend of mine pointed me to the LaTex package placeins.
#+LATEX_HEADER: \usepackage{placeins}
* section 1
** hi!
#+TITLE: fig:banana
#+CAPTION: this is a banana figure
[[/link/to/banana.png]]
\FloatBarrier
* section 2
The FloatBarrier stops floats (figures are floats) from jumping over them. I will need to look into passing [tbh] options to figures from org mode further.
Check the org-mode manual on how to pass placement options such as [h], [t] etc. to theLaTeX compiler.
If you're not sure how to control where figures (more precisely, floats) get placed by LaTeX, please refer to any introduction.
Or do you want the figure to be placed where you include it? If so, you might not need it to be a float.

Code block result as property value for a table

I'm writing my thesis in Org→Latex. As well as the individual chapter files, I keep track of the overall structure and progress in a separate file. One thing I look at and have to report on is the number of pages written versus the intended length.
I can use pdfinfo to get the number of physical pages in the individual chapters and get this into the outline with a code block. And I can generate a "columnview" table that automatically updates from the chapter info in the outline. I'd like to find out how I could put the two together.
Example
Hopefully this shows what I'm trying to do. In the real thing, there are obviously more like a dozen chapters.
#+TITLE: Thesis Outline
#+COLUMNS: %2ID %35ITEM %Target_Pages{+}
#+NAME: count-pdf-pages
#+BEGIN_SRC elisp :exports none :var pdf-file=""
(let
((pdf-file-info (shell-command-to-string (concat "pdfinfo " pdf-file))))
(string-match "Pages:[[:blank:]]+\\([0-9]+\\)" pdf-file-info)
(match-string 1 pdf-file-info)
)
#+END_SRC
* Chapter outlines
:PROPERTIES:
:ID: outlines
:END:
** 1. Introduction
:PROPERTIES:
:Target_Pages: 5
:END:
This is the introduction of the thesis. It currently has this many pages:
#+NAME: intro-page-count
#+CALL: count-pdf-pages("latex/intro-chapter.pdf")
* Page Allocation and Completion
#+BEGIN: columnview :hlines 1 :id outlines
| ID | ITEM | Target_Pages |
|----------+--------------------+--------------|
| outlines | * Chapter outlines | 5 |
| | ** 1. Introduction | 5 |
#+END
Question
What I would like to do is be able to use the return value of the CALL block for each chapter within the outline table at the end. However, having read through the relevant section of the manual a few times, I can't see whether it's possible to set a heading's property (say Written_Pages) to be the result of a code block.
Obviously, I'm also open to other org ways of approaching the problem of generating a table from the results of multiple code calls.
Org-mode properties can be set via elisp using org-set-properties. For example, (org-set-properties "Written_Pages" "5") (note that the property value must be a string. So just add an extra source block:
#+BEGIN_SRC elisp :export none :results none :var p=intro-page-count
(org-set-property "Written_Pages" p)
#+END_SRC

How to embed latex result to ODT file emacs org-mode?

In org-mode, try to push LaTex code to generate matrix like this
The code is like this:
#+BEGIN_SRC latex
\[ G_{x} = \left[ \begin{array}{ccc}
-1 & 0 & 1 \\
-2 & 0 & 2 \\
-1 & 0 & 1 \end{array} \right] {\hspace{2em}} G_{y} = \left[ \begin{array}{ccc}
-1 & -2 & -1 \\
0 & 0 & 0 \\
1 & 2 & 1 \end{array} \right] \]
#+END_SRC
But when I try to export ORG file to ODT document, the matrix are not presented. Do I need any options or configuration for my org-mode?
Thanks
Untested, but there are a couple of answers to this in the Org-mode manual, specifically they involve wrapping the snippet in \begin{equation}and \end{equation} rather than #+begin_src (which I think will result in embedding the source in the ODT), and setting an option (such as #+OPTIONS: tex:imagemagick) which will ask Org-mode to embed LaTeX as images.
http://orgmode.org/manual/Working-with-LaTeX-math-snippets.html#Working-with-LaTeX-math-snippets
Note: this may be specific to your version of Org-mode -- the exporter framework was significantly overhauled for 8.0 and I believe this documentation applies to Org-mode 8.0.