在 minipage/subfig 中缩放时控制 LaTeX 图形中的字体大小? [英] Control font size in graphics in LaTeX when scaling in minipage/subfig?

查看:182
本文介绍了在 minipage/subfig 中缩放时控制 LaTeX 图形中的字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using pgf/tikz graphics and I'm wondering how one can control the scaling of font sizes in the graphics when using them in minipage/subfig environments?

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

Is there a way to manually set a permanent font size for pgf/tikz graphics or in latex in general so as to make font sizing invariant to scaling?

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

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

Here is an example of the usage as suggested. Thanks for the help.

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

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

Perhaps outside of minipage/subfig I can use the suggestions from the other posting to make the font large since the graphic is scaled with the page width? What I was going for in the example was the first image on it's own, larger, and then two smallimages right below side by side with their own captions in one figure.

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

I saw some R tags in your profile Mica. The graphics are generated using tikzDevice and are picked up in my latex doc.

所以我在没有 tikzpicture 环境的情况下生成文件,以便我可以自己手动设置选项.当我使用 egin{tikzpicture} end{tikzpicture} 我得到错误 "Dimension too large I can't work with size greater than about 19 feet. 继续,我会使用我能做到的最大值.".我需要使用 eginpgfgraphicnamed{} .. endpgfgraphicnamed{} 让它工作?不确定具体是什么影响.

So I'm generating the files without the tikzpicture environment so that I can manually set options there myself. When I use the egin{tikzpicture} end{tikzpicture} I get the error "Dimension too large I can't work with sizes bigger than about 19 feet. Continue and I'll use the largest value I can.". I need to use eginpgfgraphicnamed{} .. endpgfgraphicnamed{} to get it to work? Not sure what the impact is exactly.

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

egin{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}
egin{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}

........

egin{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}

........

egin{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}


ode[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}
egin{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 行,所以我尝试剪掉唯一位的表示.如果您还需要什么,请告诉我.

Hopefully that is helpful, over all the file is ~1,000 lines so I tried to cut out a representation of the unique bits. Please let me know if you need anything else.

非常感谢,

推荐答案

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

I am not exactly sure what your aim is. To change the font size or the size of the Rest of the picture? There are multiple possibilities to reach any of these:

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

My example box with a 1cm x 1cm large box:

egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}

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

Scale the graphical elements, but NOT the text:

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

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

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

Scale the coordinates only (That is, if no unit is specified, it used multiplies of the specified x, y and z vector):

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

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

Explicit lengths are not changed with this:

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

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

Scale everything, even the text (according to the pgfmanual, this is not recommended):

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

使用 LaTeX 命令的效果相同:

Same effect using LaTeX commands:

scalebox{0.5}{
egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}
}

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

Change the font size locally, but the size of graphical elements are not changed:

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

在所有后续的 tikzpicture 环境中更改字体大小( ikzset 也可用于设置上述选项):

Change the font size in all subsequent tikzpicture environments ( ikzset can be used to set the options above, too):

	ikzset{font=scriptsize}
egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}

ikzset 保持本地分组:

egin{minipage}{linewidth}
	ikzset{font=scriptsize}
egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}
end{minipage}

{
	ikzset{font=scriptsize}
egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}
}

egin{tikzpicture}
    draw (0,0) rectangle (1,1) -- +(-1,-1);
    
ode(text) at (0.5,0.5) {Text};
end{tikzpicture}

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

I don't know whether you can edit the files graph?.tex, or are these generated? Maybe you can pass options to the program that generates the tikzpicture environment. Otherwise, just set the desired option in your desired scope using ikzset.

希望,这会有所帮助.

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

EDIT: If the options (like font=) are defined locally in the graph?.tex, then these get precedence over the options defined outside. If this is the case, you just can't overwrite them from the outside. You'd have to edit the files.

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

EDIT: This "minimal" example works for me (showing a really big "Mackenzie Net Sales" that exceeds the subfigure's width)

documentclass{article}

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

egin{document}
	ikzset{every picture/.append style={font=fontsize{100}{120}selectfont}}

egin{figure}[h]
centering
subfloat[Graph 1]{
    egin{minipage}[h]{0.7linewidth}
        centeringeginpgfgraphicnamed{graph1}
%        input{graph1.tex}
        endpgfgraphicnamed
        label{fig:graph1}
    end{minipage}}
hspace{5pt}
subfloat[Graph 2]{
    egin{minipage}[h]{0.5linewidth}
        centering 
        
esizebox{	extwidth}{!}{

            %eginpgfgraphicnamed{graph2}  
egin{tikzpicture}
egin{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}
egin{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}
egin{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}
egin{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}

ode[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}
egin{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]{
    egin{minipage}[h]{0.5linewidth}
        centeringeginpgfgraphicnamed{graph3}
%        input{graph3.tex}
        endpgfgraphicnamed
        label{fig:graph3}
    end{minipage}}
caption{Three Graphs}
end{figure}

end{document}

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

Please test whether this works for you, too. If it does, then try to modify this one until it doesn't work any more. What's the breaking change?

这篇关于在 minipage/subfig 中缩放时控制 LaTeX 图形中的字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆