将表格保存为 PNG

将表格保存为 PNG

我想将下表保存为 png。我试过并使用 Linux 程序 convert,但两者都保存了整个页面,而不仅仅是表格。我只想将表格保存为 png。

我怎样才能做到这一点?

\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} 

答案1

standalone您可以使用类似这样的类来获取适合内容的页面大小

\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}

如果添加png

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

并运行pdflatex--shell-escape它将自动convert在后台使用 imagemagic 并直接生成 PNG 图像而不是 PDF 输出。

相关内容