平均能量损失

平均能量损失

我有一张 pgf 图片,插入以下内容:

\input{m1.pgf}

但是图像太大了。我不想重新生成较小的图像,而是希望利用矢量图形,并让 XeLaTeX 缩放它。如何设置 pgf 图片的宽度(保持其纵横比)?

平均能量损失

文本:

\documentclass{article}

\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{DejaVu Sans}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}

% pgf:
\usepackage{pgf}

\begin{document}

\input{m1.pgf}

\end{document}

样本 pgf:文档(它太大了,无法在这里引用,而且我也无法把它弄小)。

答案1

也许只是\scalebox

\documentclass{article}

\usepackage{fontspec} % enagles loading of OpenType fonts
\usepackage{polyglossia} % support for languages

% fonts:
\defaultfontfeatures{Scale=MatchLowercase,Mapping=tex-text} % without this XeLaTeX won't turn "--" into dashes
\setmainfont{DejaVu Sans}
\setsansfont{DejaVu Sans}
\setmonofont{DejaVu Sans Mono}

% pgf:
\usepackage{pgf}

\begin{document}

\scalebox{0.6}{\input{m1.pgf}}

\end{document}

答案2

Przemysław Scherwentke 在评论中给出的答案非常有效:只需使用

\resizebox{\textwidth}{!}{\input{m1.pgf}}

答案3

您可以先绘制一个模型来确定尺寸,计算缩放因子,然后再次绘制图像:

代码

\documentclass[a5paper]{scrreprt}
\usepackage{xifthen}
\usepackage{environ}
\usepackage{tikz}

\pgfmathsetmacro{\maximumpicturewidth}{10}% max width in cm
\pgfmathsetmacro{\maximumpictureheight}{5}% max height in cm

\newcommand{\getxyscale}
{   \path (current bounding box.south west);
  \pgfgetlastxy{\xsw}{\ysw}
  \path (current bounding box.north east);
  \pgfgetlastxy{\xne}{\yne}
  \pgfmathsetlengthmacro{\picwidth}{\xne-\xsw}
  \pgfmathsetlengthmacro{\picheight}{\yne-\ysw}
  \pgfmathsetlengthmacro{\maxpicwidth}{\maximumpicturewidth*28.453}
  \pgfmathsetlengthmacro{\maxpicheight}{\maximumpictureheight*28.453}
  \pgfmathsetmacro{\xscale}{\maxpicwidth/\picwidth}
  \pgfmathsetmacro{\yscale}{\maxpicheight/\picheight}
  \xdef\xscalefactor{\xscale}
  \xdef\yscalefactor{\yscale}
}

\NewEnviron{autoscaletikz}%
{\noindent\hphantom{\vphantom{\begin{tikzpicture}\BODY\getxyscale\end{tikzpicture}}}%
\noindent\begin{tikzpicture}[xscale=\xscalefactor,yscale=\yscalefactor]\BODY\end{tikzpicture}}

\begin{document}

\begin{autoscaletikz}
    \fill[red] (0,0) circle (5 and 1);
    \fill[draw=black,left color=blue, right color=orange] (0.5,0) rectangle (4,2);
    \draw (2,-1) rectangle (18,1);
    \draw (4,-0.5)
    \foreach \x in {1,...,12}
    {   arc ({mod(\x,4)*90}:{(mod(\x,4)+1)*90}:{\x/10})
    }   ;
\end{autoscaletikz}

\end{document}

如果您想保持纵横比,只需改变环境:

\NewEnviron{autoscaletikz}%
{\noindent\hphantom{\vphantom{\begin{tikzpicture}\BODY\getxyscale\end{tikzpicture}}}%
\noindent\begin{tikzpicture}[xscale=\xscalefactor,yscale=\xscalefactor]\BODY\end{tikzpicture}}

结果

在此处输入图片描述

相关内容