我的出版商希望我的图片能够以 100% 的比例加载,这样字体大小就不会缩放,但要求宽度为 20mm、44mm、68mm、82mm 或 140mm 之一,以对应列宽(20mm+4mm 间隙)。我有几张带文本的独立图片,需要符合这些测量值之一。
最好的方法是什么?这似乎很复杂,因为需要使用不同的编译器。(我使用的是 XeLaTeX)这是一个示例文件,生成的宽度为 63 毫米,我希望将其设置为 44 毫米。
\documentclass{standalone}
\usepackage{xcolor}%RGB Definitions
\definecolor{PG-Chem}{RGB}{5,114,118}
\usepackage {tikz}
\usepackage{mathspec}
\setmainfont{Source Sans Pro}
\begin{document}
\begin {tikzpicture}[yscale=0.05]
%Define Isotopes
\pgfmathsetmacro {\isotopeAmass}{10}
\pgfmathsetmacro {\isotopeBmass}{11}
\pgfmathsetmacro {\isotopeAabundance}{19.97}
\pgfmathsetmacro {\isotopeBabundance}{80.03}
\pgfmathsetmacro {\xmin}{\isotopeAmass-2}
\pgfmathsetmacro {\xmax}{\isotopeBmass+2}
%draw Grid & axes
\draw [thick, ->] (\xmin,0)--(\xmin,100) node [midway, anchor=south, rotate=90, yshift=0.5cm]{\% Abundance}; %y-axis
\draw [thick, ->] (\xmin,0)--(\xmax,0) node [midway, anchor=north,yshift=-0.5cm]{mass/charge ratio}; %x-axis
\foreach \x in {\xmin,...,\xmax}
\draw (\x,-0.75) -- (\x ,0) node[below,anchor=north,yshift=-3pt]{\x}; %x-axis tick marks
\foreach \y in {10,20,...,100}
\draw (\xmin-0.1, \y cm) -- (\xmin, \y cm) node[above,anchor=east]{\y}; %y-axis tick marks
\foreach \g in {10,20,...,100}
\draw[gray!50,very thin] (\xmin, \g ) -- (\xmax, \g ); %horizontal grid
%Draw spectrum
\draw[line width=2pt,PG-Chem] (\isotopeAmass,0)--(\isotopeAmass,\isotopeAabundance) node [above, anchor=south]{\isotopeAabundance \%};
\draw[line width=2pt,PG-Chem] (\isotopeBmass,0)--(\isotopeBmass,\isotopeBabundance)node [above, anchor=south]{\isotopeBabundance \%};
\end{tikzpicture}
\end{document}
答案1
与standalone
其他文档类一样,您无法规定图像的宽度。图像的宽度始终由图像本身定义。
就你的情况而言,最接近你想要实现的是使用pgfplots
包来绘制图表。使用它,你可以相当简单地通过axis
选项 ˙width= . Beside this, using
pgfplots` 规定图像宽度,图表代码更简单、更一致:
% XeTeX
\documentclass{standalone}
\usepackage{mathspec}
\setmainfont{Source Sans Pro}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\definecolor{PG-Chem}{RGB}{5,114,118}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=82mm, % <--- width of image
axis lines=left,
axis line style = {thick},
ybar,
bar width=2pt, % you may define wider width: 4pt or even more
ymajorgrids,
xlabel = {\% Abundance},
ylabel = {mass/charge ratio},
xmin=8, xmax=13,
ymin=0, ymax=100,
ytick distance = 10,
nodes near coords={\pgfmathprintnumber\pgfplotspointmeta\,\%},
]
%Draw spectrum
\addplot [draw=PG-Chem, fill=PG-Chem] coordinates { (10, 19.97) (11, 80.03) };
\end{axis}
\end{tikzpicture}
\end{document}