【问题标题】:Control font size in graphics in LaTeX when scaling in minipage/subfig?在 minipage/subfig 中缩放时控制 LaTeX 图形中的字体大小?
【发布时间】:2010-02-10 18:25:56
【问题描述】:

我正在使用 pgf/tikz 图形,我想知道在 minipage/subfig 环境中使用图形时如何控制图形中字体大小的缩放?

有没有办法为 pgf/tikz 图形或一般的乳胶手动设置永久字体大小,以使字体大小不受缩放影响?

理想情况下,我希望能够为每个图形或所有图形或 subfig/minipage 环境手动指定字体大小?

以下是建议的用法示例。感谢您的帮助。

\begin{figure}[h]
\centering
\subfloat[Graph 1]{
    \begin{minipage}[h]{0.7\linewidth}
        \centering\beginpgfgraphicnamed{graph1}
        \input{graph1.tex}
        \endpgfgraphicnamed
        \label{fig:graph1}
    \end{minipage}}
\hspace{5pt}
\subfloat[Graph 2]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph2}
        \input{graph2.tex}
        \endpgfgraphicnamed
        \label{fig:graph2}
    \end{minipage}}
\subfloat[Graph 3]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph3}
        \input{graph3.tex}
        \endpgfgraphicnamed
        \label{fig:graph3}
    \end{minipage}}
\caption{Three Graphs}
\end{figure}

也许在 minipage/subfig 之外我可以使用其他帖子中的建议来使字体变大,因为图形是按页面宽度缩放的?我在这个例子中想要的是第一张图片,更大的,然后是两个小图片并排在下面,并在一个图中有自己的标题。

我在您的个人资料 Mica 中看到了一些 R 标签。图形是使用 tikzDevice 生成的,并在我的 Latex 文档中提取。

所以我在没有 tikzpicture 环境的情况下生成文件,这样我就可以自己手动设置选项。当我使用\begin{tikzpicture} \end{tikzpicture} 时,我收到错误“尺寸太大,我无法使用大于约 19 英尺的尺寸。继续,我将使用我能使用的最大值。”。我需要使用\beginpgfgraphicnamed{} .. \endpgfgraphicnamed{} 让它工作吗?不确定具体是什么影响。

这是自动生成文件的示例:

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}

........

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{fillColor}{rgb}{1.00,1.00,1.00}

\draw[fill=fillColor,draw opacity=0.00,] (  0.00,  0.00) rectangle (794.97,614.29);
\end{scope}

........

\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}

\node[rotate= 90.00,color=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 15.92,310.59) {Mackenzie Net Sales};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (794.97,614.29);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}

希望这会有所帮助,因为整个文件大约有 1,000 行,所以我尝试删除唯一位的表示。如果您还需要什么,请告诉我。

非常感谢,

【问题讨论】:

  • 实际代码仍然有用。你为什么要缩放 tikz/pgf 绘图?为什么不把它画到合适的大小呢?

标签: latex tikz pgf subfigure


【解决方案1】:

我不确定你的目标是什么。要更改字体大小或图片其余部分的大小?有多种可能性可以达到其中任何一个:

我的示例盒子有一个 1cm x 1cm 的大盒子:

\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

缩放图形元素,但不缩放文本:

\begin{tikzpicture}[scale=0.5]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

\begin{tikzpicture}[scale=0.5]
    \draw (0,0) rectangle (1cm,1cm) -- +(-1,-1);
    \node(text) at (0.5cm,0.5cm) {Text};
\end{tikzpicture}

仅缩放坐标(即,如果未指定单位,则使用指定 x、y 和 z 向量的乘积):

\begin{tikzpicture}[x=5mm,y=5mm]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

显式长度不会因此而改变:

\begin{tikzpicture}[x=5mm,y=5mm]
    \draw (0,0) rectangle (1cm,1cm) -- +(-1cm,-1cm);
    \node(text) at (0.5cm,0.5cm) {Text};
\end{tikzpicture}

缩放所有内容,甚至是文本(根据 pgfmanual,不建议这样做):

\begin{tikzpicture}[transform canvas={scale=0.5}]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

使用 LaTeX 命令的效果相同:

\scalebox{0.5}{
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
}

在本地更改字体大小,但图形元素大小不变:

\begin{tikzpicture}[font=\scriptsize]
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

在后续所有tikzpicture环境中更改字体大小(\tikzset也可以用来设置上面的选项):

\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

\tikzset 保持本地分组:

\begin{minipage}{\linewidth}
\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
\end{minipage}

{
\tikzset{font=\scriptsize}
\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}
}

\begin{tikzpicture}
    \draw (0,0) rectangle (1,1) -- +(-1,-1);
    \node(text) at (0.5,0.5) {Text};
\end{tikzpicture}

不知道graph?.tex的文件是否可以编辑,还是这些生成的?也许您可以将选项传递给生成tikzpicture 环境的程序。否则,只需使用 \tikzset 在所需范围内设置所需选项。

希望,这会有所帮助。

编辑: 如果选项(如font=)在graph?.tex 中本地定义,则这些选项优先于外部定义的选项。如果是这种情况,您就不能从外部覆盖它们。您必须编辑文件。

编辑:这个“最小”示例对我有用(显示了一个非常大的“Mackenzie Net Sales”,超出了子图的宽度)

\documentclass{article}

\usepackage{fix-cm}
\usepackage{subfig}
\usepackage{tikz}

\begin{document}
\tikzset{every picture/.append style={font=\fontsize{100}{120}\selectfont}}

\begin{figure}[h]
\centering
\subfloat[Graph 1]{
    \begin{minipage}[h]{0.7\linewidth}
        \centering\beginpgfgraphicnamed{graph1}
%        \input{graph1.tex}
        \endpgfgraphicnamed
        \label{fig:graph1}
    \end{minipage}}
\hspace{5pt}
\subfloat[Graph 2]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering 
        \resizebox{\textwidth}{!}{

            %\beginpgfgraphicnamed{graph2}  
\begin{tikzpicture}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{fillColor}{rgb}{1.00,1.00,1.00}
\draw[fill=fillColor,draw opacity=0.00,] (  0.00,  0.00) rectangle (79.497,61.429);
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\definecolor[named]{drawColor}{rgb}{0.00,0.00,0.00}
\node[rotate= 90.00,color=drawColor,anchor=base,inner sep=0pt, outer sep=0pt, scale=  1.00] at ( 1.592,31.059) {Mackenzie Net Sales};
\end{scope}
\begin{scope}
\path[clip] (  0.00,  0.00) rectangle (79.497,61.429);
\definecolor[named]{drawColor}{rgb}{0.13,0.76,0.43}
\definecolor[named]{fillColor}{rgb}{0.31,0.94,0.66}
\end{scope}
\end{tikzpicture}
}
        %\endpgfgraphicnamed

        \label{fig:graph2}
    \end{minipage}}
\subfloat[Graph 3]{
    \begin{minipage}[h]{0.5\linewidth}
        \centering\beginpgfgraphicnamed{graph3}
%        \input{graph3.tex}
        \endpgfgraphicnamed
        \label{fig:graph3}
    \end{minipage}}
\caption{Three Graphs}
\end{figure}

\end{document}

请测试这是否也适合您。如果是这样,那么尝试修改这个,直到它不再工作为止。什么是重大变化?

【讨论】:

  • 如果您能发布这样的input?.tex 文件会很有帮助。可能您可以使用样式设置大小。
  • 试试\tikzset{every picture/.append style={font=\scriptsize}}这行得通吗?
  • 不需要是完整的文件。既然是生成的,很多东西只是sn-ps的重复。只显示最重要部分的摘录(包括开头)。
  • 你是怎么排版的?我只是得到“尺寸太大”。但是,在将所有坐标除以 10 后,它起作用了。
  • 派对有点晚了,但“尺寸太大”错误是由于 TikZ 默认为坐标单位为 1cm 而 tikzDevice 输出假定为 1pt。要在不进行任何疯狂划分的情况下修复问题,请在处理 tikzDevice 输出时使用\begin{tikzpicture}[x=1pt, y=1pt]\begin{scope}[x=1pt, y=1pt]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-24
  • 1970-01-01
  • 2018-02-02
相关资源
最近更新 更多