0

I'd like to save the following table as png. I've tried this and using the Linux program convert, but both saved the whole page instead of just the table. I want to save just the table as png.

How can I do this?

\documentclass[11pt]{article}
\usepackage[table]{xcolor}

\definecolor{myblue}{RGB}{78, 126, 222}
\usepackage{multirow}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}

\begin{document}

\begin{table}[ht]
    \centering\setlength{\extrarowheight}{3pt}
\rowcolors{1}{myblue}{}
        \begin{tabularx}{\textwidth}{>{\cellcolor{white}} c >{\cellcolor{white}}c>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X}
            \toprule
            & Inner index 1.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \multirow{-2}{*}{Outer index 1} & Inner index 1.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \midrule
             & Inner index 2.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \multirow{-2}{*}{Outer index 2} & Inner index 2.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \midrule& Inner index 3.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            &Inner index 3.2 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.3 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            \multirow{-2}{*}{Outer index 3}&Inner index 3.4 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.5 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.6 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            \bottomrule
        \end{tabularx}
\end{table}

\end{document} 
  • Produce the PDF, open it with Photoshop and then save it as the format of PNG. – Mogic Mar 21 at 1:02
  • Even if I took your suggestion seriously, it doesn't address the issue of it saving the whole page. @Kuttens – whoami Mar 21 at 1:08
  • remove the table environment and just have the tabular, and use standalone class not article and the page will be resized to the table, the class has options to auto-generate the image formats as well – David Carlisle Mar 21 at 1:14
  • @DavidCarlisle Close! That made me loose the bottom line of the table. Otherwise, if you were to answer with that, I would accept it. Can you find a solution to this and answer, please? – whoami Mar 21 at 1:18
  • too late to check now but I think you will find the class has some options to add a bit of white space padding before it clips, too late to check now, feel free to self answer if you get something working – David Carlisle Mar 21 at 1:19
2

You can get a page sized to the content using the standalone class something like

\documentclass[border={0pt 40pt 40pt 0pt}]{standalone}

\usepackage[table]{xcolor}

\definecolor{myblue}{RGB}{78, 126, 222}

\usepackage{multirow}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{ragged2e}


\begin{document}

\begin{tabularx}{\textwidth}{>{\cellcolor{white}} c >{\cellcolor{white}}c>{\RaggedRight\arraybackslash}X>{\RaggedRight\arraybackslash}X}
            \toprule
            & Inner index 1.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \multirow{-2}{*}{Outer index 1} & Inner index 1.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \midrule
             & Inner index 2.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \multirow{-2}{*}{Outer index 2} & Inner index 2.2 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            \midrule& Inner index 3.1 & Text data placeholder. May be long enough that it needs to be wrapped. & Text data placeholder. May be long enough that it needs to be wrapped.\\
            &Inner index 3.2 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.3 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            \multirow{-2}{*}{Outer index 3}&Inner index 3.4 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.5 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            &Inner index 3.6 & \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep+\arrayrulewidth\relax\RaggedRight\arraybackslash}X}{ Text data placeholder. May be long enough that it needs to be wrapped. Text data placeholder. May be long enough that it needs to be wrapped.}\\
            \bottomrule
        \end{tabularx}
\end{document}

If you add png:

\documentclass[border={0pt 40pt 40pt 0pt},png]{standalone}

and run pdflatex with --shell-escape then it will automatically use imagemagic convert in the background and directly produce a PNG image rather than PDF outpuput.

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.