我用 LaTeX 为我的论文制作了不少图表。现在我想将其中大约五个图表导出为具有清晰背景的 .png,以便在 PowerPoint 演示文稿中使用它们。我正在使用 TexStudio 和 MikTex。我找到了一些关于此内容的旧帖子(通过命令行将 TeX 转换为图像,如何在徽标中创建透明背景?,如何去除 png 图片的背景,制作具有透明背景的图像),但似乎没有一个能回答我的问题。
例图:
\PassOptionsToPackage{table,dvipsnames,svgnames}{xcolor}
\documentclass[11pt, twoside, a4paper]{report}
\usepackage[inner = 30mm, outer = 20mm, top = 30mm, bottom = 20mm, headheight = 13.6pt]{geometry}
\usepackage{tikz}
\usepackage[pdfpagelayout=TwoPageRight]{hyperref}
\usepackage[export]{adjustbox}
%\usepackage{showframe}
\hypersetup{colorlinks=true, linktoc=all, allcolors=green!30!black,}
\usepackage{pgfplots}
\pgfplotsset{
compat=1.16,
%made the beginnings of a second axis style, because I figured it needs to be different for grouped
my second axis style/.style={
width=\linewidth,
height=0.35\linewidth,
bar width=0.2, %<- changed
enlarge x limits={abs=0.45}, % <-- changed to absolute coordinates
ymin=0,
legend style={
at={(0.5,1.15)}, % <-- adapted
anchor=north, % <-- changed from `north'
legend columns=3,
},
ylabel={PR\textsubscript{A}},
xtick=data,
axis lines*=left,
ymajorgrids,
%
table/x=x,
},
% created a style for the common `ybar' options
my second ybar style/.style={
ybar,
my ybar legend, % <-- change legend image accordingly
#1!50!black,
fill=white!70!black,, %<- changed back
nodes near coords, % <-- moved from `axis' options here
% state absolute positions for the `nodes near coords'
scatter/position=absolute,
node near coords style={
% state where the nodes should appear
at={(\pgfkeysvalueof{/data point/x},0.5*\pgfkeysvalueof{/data point/y})},
anchor=center,rotate=90, %<-added
% make the font a bit smaller
font=\footnotesize,
/pgf/number format/.cd,
fixed,
precision=2,
zerofill,
},
},
my ybar legend/.style={
/pgfplots/legend image code/.code={
\draw [
##1,
/tikz/.cd,
yshift=-0.25em,
] (0cm,0cm) rectangle (3pt,0.8em);
},
},
}
%data for the grouped bar chart
\pgfplotstableread{
x SP_cSi_2_3 SP_cSi_2_4 Reference
1 0.500 0.627 0.868
2 0.781 0.778 0.859
3 0.819 0.868 0.871
4 0.732 0.824 0.876
5 0.853 0.873 0.954
6 0.813 0.838 0.940
7 0.712 0.759 0.876
8 0.864 0.894 0.887
9 0.465 0.614 0.891
}{\loadedtablesppr}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[my second axis style,
ybar,
ylabel={PR\textsubscript{A}},
xtick= data,
]
\addplot [my second ybar style=blue!50!black,] table [y=SP_cSi_2_3] {\loadedtablesppr};
\addplot [my second ybar style=orange!50!black,] table [y=SP_cSi_2_4] {\loadedtablesppr};
\addplot [my second ybar style=red!50!black,] table [y=Reference] {\loadedtablesppr};
\legend{Floating 2.3~~ , Floating 2.4~~ , Reference}
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
是否有类似的命令
\savefig{'my_export_image.png', clear = True}
?
答案1
如果只是 tikz 图片,你可以尝试使用 Troy Henderson 的 Latex Previewerhttp://www.tlhiv.org/ltxpreview/。只需在“包”下添加 tikz 包,然后您可以选择想要的输出类型 - 例如 png。
最近发现它并且运行得很好!