简体   繁体   English

在minipage / subfig中缩放时,控制LaTeX中图形的字体大小?

[英]Control font size in graphics in LaTeX when scaling in 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图形,我想知道在minipage / subfig环境中使用它们时如何控制图形中字体大小的缩放?

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? 有没有办法手动设置pgf / tikz图形或乳胶中的永久字体大小,以便使字体大小不变为缩放?

Ideally I'd like to be able to manually specify a font size per graphic or for all graphics or subfig/minipage environments? 理想情况下,我希望能够为每个图形或所有图形或子图形/小型化环境手动指定字体大小?

Here is an example of the usage as suggested. 以下是建议使用的示例。 Thanks for the help. 谢谢您的帮助。

\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}

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? 也许在minipage / subfig之外我可以使用其他帖子的建议来使字体变大,因为图形是用页面宽度缩放的? 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. 在这个例子中我想要的是它自己的第一个图像,更大,然后是两个小图像,并排在一个图中,并排在一起。

I saw some R tags in your profile Mica. 我在你的个人资料Mica中看到了一些R标签。 The graphics are generated using tikzDevice and are picked up in my latex doc. 图形是使用tikzDevice生成的,并在我的latex文档中提取。

So I'm generating the files without the tikzpicture environment so that I can manually set options there myself. 所以我在没有tikzpicture环境的情况下生成文件,以便我可以自己手动设置选项。 When I use the \\begin{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." 当我使用\\begin{tikzpicture} \\end{tikzpicture}我得到的错误是“尺寸过大我不能使用大于19英尺的尺寸。继续,我将使用最大的值。” . I need to use \\beginpgfgraphicnamed{} .. \\endpgfgraphicnamed{} to get it to work? 我需要使用\\beginpgfgraphicnamed{} .. \\endpgfgraphicnamed{}来使它工作? Not sure what the impact is exactly. 不确定影响究竟是什么。

Here is a sample of the auto-generated file: 以下是自动生成文件的示例:

\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}

Hopefully that is helpful, over all the file is ~1,000 lines so I tried to cut out a representation of the unique bits. 希望这是有帮助的,所有文件都是~1,000行,所以我试图删除唯一位的表示。 Please let me know if you need anything else. 如果您还有其他需要,请告诉我。

Many thanks, 非常感谢,

Jay 松鸦

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: 有多种可能性来实现这些目标:

My example box with a 1cm x 1cm large box: 我的示例盒子有一个1厘米x 1厘米的大盒子:

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

Scale the graphical elements, but NOT the text: 缩放图形元素,但不是文本:

\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}

Scale the coordinates only (That is, if no unit is specified, it used multiplies of the specified x, y and z vector): 仅缩放坐标(即,如果未指定单位,则使用指定的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}

Explicit lengths are not changed with this: 显式长度不会随此改变:

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

Scale everything, even the text (according to the pgfmanual, this is not recommended): 扩展所有内容,甚至文本(根据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}

Same effect using LaTeX commands: 使用LaTeX命令的效果相同:

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

Change the font size locally, but the size of graphical elements are not changed: 在本地更改字体大小,但图形元素的大小不会更改:

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

Change the font size in all subsequent tikzpicture environments ( \\tikzset can be used to set the options above, too): 在所有后续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 remains local in groups: \\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}

I don't know whether you can edit the files graph?.tex , or are these generated? 我不知道你是否可以编辑文件graph?.tex ,还是这些是生成的? Maybe you can pass options to the program that generates the tikzpicture environment. 也许你可以将选项传递给生成tikzpicture环境的程序。 Otherwise, just set the desired option in your desired scope using \\tikzset . 否则,只需使用\\tikzset在所需范围内设置所需选项。

Hope, that helps. 希望,这有帮助。

EDIT : If the options (like font= ) are defined locally in the graph?.tex , then these get precedence over the options defined outside. 编辑 :如果选项(如font= )在graph?.tex本地定义graph?.tex ,那么这些选项优先于外部定义的选项。 If this is the case, you just can't overwrite them from the outside. 如果是这种情况,您就无法从外部覆盖它们。 You'd have to edit the files. 你必须编辑文件。

EDIT : This "minimal" example works for me (showing a really big "Mackenzie Net Sales" that exceeds the subfigure's width) 编辑 :这个“最小”的例子适用于我(显示超过子图宽度的非常大的“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}

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? 什么是突破性变化?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM