1

This latex code intents to produce a stand alone picture of a table.

I have the following latex code that has been generated under Rstudio by a xtable function and encapsulated by me (code lines surrounding the begin/end table's code) :

\documentclass[crop=true, varwidth=true]{standalone}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{rotating}
\usepackage{graphicx}
\begin{document}
\setlength\tabcolsep{2pt}
% latex table generated in R 3.3.2 by xtable 1.8-2 package
\begin{table}[ht]
\centering
\begin{tabular}{rlll}
\hline
& \begin{sideways} CA \end{sideways} & \begin{sideways} CB \end{sideways} &     \begin{sideways} CC \end{sideways} \\ 
\hline
RA & 1 & 4 & 7 \\ 
RB & 2 & 5 & 8 \\ 
RC & 3 & 6 & 9 \\ 
\hline
\end{tabular}
\end{table}
\end{document}

I generate a .png picture with the 2 following lines based on Windows10/Miktex2.9 :

pdflatex.exe -output-format=dvi ./drugs_cross_tex.tex
dvipng.exe -T tight -D 600 -z 9 -q -o ./drugs_cross_tex.png ./drugs_cross_tex.dvi

Unfortunatly, the .png picture produced is incorrect because the 3 columns (CA, CB, CC) are not 90 deg rotated (but they are shifted to the right).

enter image description here

Here is the log file : click here to download

Anyone can tell me how to make this latex code working ?

  • 1
    Welcome to TeX.SX! Why not doing the conversion to PNG directly with standalone? – egreg Feb 10 '17 at 18:05
  • Hello egreg, I don't understand what you mean by "doing the conversion to PNG directly with standalone". I run Rstudio. The xtable function produce the latex code (the part of code starting by \begin{table} and ending by \end{table}) and dump it in a file. the header and footer code lines has been added by me to make it works with the "latex to dvi" processor. What I need is just to make pictures (of statistic tables) without having to use complex Tools such as sweave, knitr, lyx, ... – Syl87 Feb 10 '17 at 18:17
  • 1
    Apparently dvipng doesn't understand the dvips special for rotation. – egreg Feb 10 '17 at 18:19
  • You'r right! It was dvipng. In pdf output format, both "sideways" and "rotatebox" methods work. Now I need to find another way to get a picture file with Miktex Tools... – Syl87 Feb 10 '17 at 18:32
2

If you have ImageMagick installed, then you can simply run

pdflatex -shell-escape

on the file

\documentclass[convert={density=1200}]{standalone}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{rotating}
\usepackage{graphicx}
\begin{document}
\setlength\tabcolsep{2pt}
% latex table generated in R 3.3.2 by xtable 1.8-2 package
\begin{tabular}{rlll}
\hline
& \begin{sideways} CA \end{sideways} & 
  \begin{sideways} CB \end{sideways} &     
  \begin{sideways} CC \end{sideways} \\
\hline
RA & 1 & 4 & 7 \\
RB & 2 & 5 & 8 \\
RC & 3 & 6 & 9 \\
\hline
\end{tabular}
\end{document}

(I removed the useless table environment, so also varwidth is unnecessary.)

This will produce a PNG at 1200 dpi (use the resolution you prefer).

Read section 4.6.2 in the manual of standalone for some quirks about Windows.

Here's the PNG I get

enter image description here

(I added the block quote to show it's transparent).

1

You are using sideways, but this is not indented for a situation like that. Use \rotatebox instead. If you want a little space above the headings, use something like \rotatebox{90}{Title~}.

rotated

\documentclass[crop=true, varwidth=true]{standalone}
\usepackage{xcolor}
\usepackage{colortbl}
\usepackage{rotating}
\usepackage{graphicx}
\begin{document}
\setlength\tabcolsep{2pt}
% latex table generated in R 3.3.2 by xtable 1.8-2 package
\begin{table}[ht]
\centering
\begin{tabular}{rlll}
\hline
& \rotatebox{90}{CA} & \rotatebox{90}{CB} & \rotatebox{90}{CC}\\ 
\hline
RA & 1 & 4 & 7 \\ 
RB & 2 & 5 & 8 \\ 
RC & 3 & 6 & 9 \\ 
\hline
\end{tabular}
\end{table}
\end{document}
  • Hello TeXnician, Your code seems correctly processed (no error) but the result is the same for me (header not rotated, but shifted to right). Thus, the problem seems to come from MikTex pdflatex and/or dvipng ... any idea ? – Syl87 Feb 10 '17 at 18:20
  • @Syl87 Please compile your code using pdflatex into a PDF file. If that's correct then it's probably a problem with dvipng. Probably you should follow egreg's suggestion and do the conversion via standalone class. – TeXnician Feb 10 '17 at 18:22
  • Yes! With pdf output format, both codes (sideways and rotatebox) worked! :-) But, do you know how can I simply output a picture (any format : png, jpg, svg, ...) with the Miktex Tools (or another simple tool chain) ? – Syl87 Feb 10 '17 at 18:30
  • @Syl87 If you do not want to use screenshot, you should have a look at tex.stackexchange.com/a/11880/124577 (the updated solution). – TeXnician Feb 10 '17 at 18:32
  • Ok, thanks a bunch for your help and the link. – Syl87 Feb 10 '17 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.