pgfkeys 传递字体命令

pgfkeys 传递字体命令

我正在使用pgfkeys命令定义选项。

\newcommand{\subtitlefont}{}
\pgfkeys{
   /titleblock/.is family, /titleblock,
   default/.style = 
       {titlesize = 48, titlelineskip = 52,
        subtitlesize = 36, subtitlelineskip = 39, subtitlefont=\itshape,
       },
   titlesize/.estore in = \titlesize,
   titlelineskip/.estore in = \titlelineskip,
   subtitlesize/.estore in = \subtitlesize,
   subtitlelineskip/.estore in = \subtitlelineskip,
   subtitlefont/.add code={}{\subtitlefont},
}

我想在节点字体选项中使用此选项。

\node[align=left, inner sep=0mm, outer sep=0mm,
 font={\fontsize{\subtitlesize}{\subtitlelineskip}\subtitlefont\selectfont},
 text=\titleblockcolor,
 below= 0.1cm of title.south west, anchor=north west] (subtitle) {
   \thesubtitle%
   };

该文件汇编但\itshape副标题未选中。定义由可传递给节点选项的宏组成的选项的最佳方法是什么?

完成 MWE

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfkeys}

\newcommand{\subtitlefont}{}
\pgfkeys{
   /titleblock/.is family, /titleblock,
   default/.style = 
       {
         subtitlesize = 36, subtitlelineskip = 39, subtitlefont=\itshape,
       },
   subtitlesize/.estore in = \subtitlesize,
   subtitlelineskip/.estore in = \subtitlelineskip,
   subtitlefont/.add code={}{\subtitlefont},
}



\newcommand{\titleblock}[1][]{%
\pgfkeys{/titleblock, default, #1}%
\begin{tikzpicture}
  \node[align=left, inner sep=0mm, outer sep=0mm,
  font={\fontsize{\subtitlesize}{\subtitlelineskip}\subtitlefont\selectfont},
  text=black] (subtitle) {A nice title};
\end{tikzpicture}

}

\begin{document}
\titleblock
\end{document}

答案1

pgfmanual第 889 页开始

在此处输入图片描述

因此,您应该使用store in而不是estore in。 也可以使用subtitlefont/.add code={}{\subtitlefont},而不是subtitlefont/.store in=\subtitlefont,。 此外,由于您使用的是大字体,因此最好使用lmodern提供良好可缩放字体的包,这样您就不会收到警告。

有了这些你的代码就变成了

\documentclass{article}

\usepackage{tikz}
\usepackage{pgfkeys}
\usepackage{lmodern}

\newcommand{\subtitlefont}{}
\pgfkeys{
   /titleblock/.is family, /titleblock,
   default/.style =
       {
         subtitlesize = 36, subtitlelineskip = 39, subtitlefont=\itshape,
       },
   subtitlesize/.store in = \subtitlesize,
   subtitlelineskip/.store in = \subtitlelineskip,
   subtitlefont/.store in=\subtitlefont,
}



\newcommand{\titleblock}[1][]{%
\pgfkeys{/titleblock, default, #1}%
\begin{tikzpicture}
  \node[align=left, inner sep=0mm, outer sep=0mm,
  font={\fontsize{\subtitlesize}{\subtitlelineskip}\subtitlefont\selectfont},
  text=black] (subtitle) {A nice title};
\end{tikzpicture}

}

\begin{document}
\titleblock
\end{document}

在此处输入图片描述

相关内容