如何使用独立的 pgfplot 控制字体大小

如何使用独立的 pgfplot 控制字体大小

我想控制嵌入式独立 pgfplot 的字体大小。我通过定义一个\newcommand(参见 MWE) 实现了它。

我的问题是,有没有更好的解决方案?

也许我应该提一下,情节tikzpic.texmatlab2tikz

MWE.tex:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{standalone}

\begin{document}

\begin{figure}
\centering
\newlength{\figHeight}%
\newlength{\figWidth}%
\setlength{\figHeight}{3.5cm}%
\setlength{\figWidth}{7.5cm}%
\newcommand{\myFontSize}{\normalsize}%
\includestandalone{./tikzpic}
\caption{Caption}
\label{figure1}
\end{figure}

\end{document}

tikzpic.tex:

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}
%
%\newlength{\figHeight}%
%\newlength{\figWidth}%
%\setlength{\figHeight}{5.5cm}%
%\setlength{\figWidth}{14cm}%
%\newcommand{\myFontSize}{\footnotesize}%
%
\begin{document}
\begin{tikzpicture}[font={\myFontSize}] 

\begin{axis}[%
width=0.951\figWidth,
height=\figHeight,
at={(0\figWidth,0\figHeight)},
scale only axis,
xmin=-110.00,
xmax=110.00,
xlabel={ x-Label },
ymin=-0.10,
ymax=3.10,
ylabel={ y-Label },
xmajorgrids,
ymajorgrids,
legend style={at={(0.5,0.03)}, anchor=south},
xtick align=outside,
xtick pos=bottom,
xticklabel style={align=center, text width=1em, /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=0, /pgf/number format/use comma, /pgf/number format/1000 sep={\,}, scaled x ticks = false},
xlabel style={ font={\myFontSize\color{black}} },
ytick distance=0.5,
ytick align=outside,
ytick pos=left,
yticklabel style={align=center, text width=1em, /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=1, /pgf/number format/use comma, /pgf/number format/1000 sep={\,} scaled y ticks = false},
ylabel style={ font={\myFontSize\color{black}} },
legend style={ font={\myFontSize\color{black}} },
]
\addplot [color=black, line width=1.5pt]
  table[row sep=crcr]{%
-100.00 1.\\
100.00  2.\\
};
\addlegendentry{LegendEntry}

\end{axis}
\end{tikzpicture}%

\end{document}

答案1

一种可能的解决方案是使用\pgfplotsset。在此设置中,可以使用不同的控制方式。您的tikzpic.tex。在此设置中,可以使用不同的控制方式。您的文件

主文件:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{standalone}
\newlength{\figHeight}%
\newlength{\figWidth}%
\setlength{\figHeight}{3.5cm}%
\setlength{\figWidth}{7.5cm}%
\begin{document}

\begin{figure}
\centering

%\newcommand{\myFontSize}{\Large}%
\pgfplotsset{every axis/.append style={
  y label style={font=\Huge},
  x label style={font=\Huge},
  tick label style={font=\Huge},
  legend style={nodes={scale=1, transform shape}}, 
  legend style={at={(0.5,0.03)}, anchor=south},
  every tick label/.append style={font=\fontsize{13}{20}\selectfont}  
                    }}
\includestandalone{./tikzpic}
\caption{Caption}
\label{figure1}
\end{figure}

\begin{figure}
\centering
\pgfplotsset{every axis/.append style={
  y label style={font=\large},
  x label style={font=\Huge},
  tick label style={font=\Huge},
  legend style={nodes={scale=1.5, transform shape}}, 
  legend style={at={(0.5,0.03)}, anchor=south},
  every tick label/.append style={font=\fontsize{13}{20}\selectfont}  
                    }}
\includestandalone{./tikzpic}
\caption{Caption}
\label{figure2}
\end{figure}
\end{document}

tikzpic.tex:

\documentclass[tikz]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\usepackage{grffile}
\pgfplotsset{compat=newest}
\usetikzlibrary{plotmarks}
\usetikzlibrary{arrows.meta}
\usepgfplotslibrary{patchplots}
\usepackage{amsmath}
%
%\newlength{\figHeight}%
%\newlength{\figWidth}%
%\setlength{\figHeight}{5.5cm}%
%\setlength{\figWidth}{14cm}%
%\newcommand{\myFontSize}{\footnotesize}%
%
\begin{document}
\begin{tikzpicture}%[font={\myFontSize}] 

\begin{axis}[%
width=0.951\figWidth,
height=\figHeight,
at={(0\figWidth,0\figHeight)},
scale only axis,
xmin=-110.00,
xmax=110.00,
xlabel={ x-Label },
ymin=-0.10,
ymax=3.10,
ylabel={ y-Label },
xmajorgrids,
ymajorgrids,
%legend style={at={(0.5,0.03)}, anchor=south},
xtick align=outside,
xtick pos=bottom,
xticklabel style={align=center, text width=1em, /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=0, /pgf/number format/use comma, /pgf/number format/1000 sep={\,}, scaled x ticks = false},
%xlabel style={ font={\color{black}} },
ytick distance=0.5,
ytick align=outside,
ytick pos=left,
yticklabel style={align=center, text width=1em, /pgf/number format/fixed, /pgf/number format/fixed zerofill, /pgf/number format/precision=1, /pgf/number format/use comma, /pgf/number format/1000 sep={\,} scaled y ticks = false},
%ylabel style={ font={\color{black}} },
legend style={ font={\color{black}} },
]
\addplot [color=black, line width=1.5pt]
  table[row sep=crcr]{%
-100.00 1.\\
100.00  2.\\
};
\addlegendentry{LegendEntry}

\end{axis}
\end{tikzpicture}%

\end{document}

使用我的设置输出: 在此处输入图片描述

相关内容