
我有很多資訊要寫在譜系樹上。我想將其一部分寫在樹中,其餘部分寫在下一頁上,單擊人名即可訪問。
樹是使用套件創建的genealogytree
,資料儲存在單獨的檔案中測試資料庫.tex。
我嘗試創建一個\newcommand
來列印資料庫中的數據,但沒有列印任何內容。有人可以向我解釋如何將參數正確傳遞到新命令嗎?
最終目標是列印所有人的數據,理想情況下無需在新定義的命令中鍵入每個名稱來列印其數據。
微量元素
測試文件
\documentclass{article}
\usepackage[all]{genealogytree}
\begin{document}
% Define new keys in genealogytree database
\pgfkeys{/gtr/database/.cd,
nationality/.store in=\nationality,
nationality=unknown,
given name/.store in=\givenname,
family name/.store in=\familyname,
language/.store in=\language
}
% Define new format for genealogytree
\gtrDeclareDatabaseFormat{xTestFormat}
{
% Define box title based on nationality
\ifdefined\nationality
\gtrset{box={title=\nationality}}
\fi
% Define tcolorbox parameters based on 'nationality' key
\tcbset{unknown/.style={colback=black!5!white,colframe=black}}
\tcbset{french/.style={colback=blue!5!white,colframe=blue}}
\tcbset{british/.style={colback=red!5!white,colframe=red}}
}
{ % Define informations to print in the box
\gtrPrintSex~\textcolor{blue}{\textbf{\givenname}}
\ifdefined\familyname
\familyname
\fi
\language
\gtrifcommentdefined{\gtrPrintComment}{}
}
\input{test_database}
% Create a command to print people complete data
\newcommand\PrintCompletePeople[1]{
This is the direct output: #1
I want to know what is behind the key:
\pgfkeys{/mydata/.cd,
nationalitybis/.store in=\nationalitybis,
nationalitybis=\pgfkeysvalueof{/gtr/database/people/#1/nationality}
}
\nationalitybis
but nothing is printed
}
\begin{tikzpicture}
\genealogytree[
timeflow=down,
processing=database,
database format=xTestFormat,
box={\nationality}
]
{child[id=fam_Water]{
p[id=Justine]{people=JustineID}
g[id=Tom]{people=TomID}
c[id=Jane]{people=JaneID}
}
}
\end{tikzpicture}
\newpage
\PrintCompletePeople{JaneID}
\end{document}
測試資料庫.tex
% Create database
% Jane Water
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/JaneID/.style={
female,
nationality = british,
given name = Jane,
family name = Water,
language = {English},
comment = {Something else}
}
}
% Justine Random
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/JustineID/.style={
female,
nationality = french,
given name = Justine,
language = {French, English},
% family name = Random,
comment = {Something interesting}
}
}
% Tom Water
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/TomID/.style={
male,
nationality = british,
given name = Tom,
family name = Water,
language = {English},
% comment = {There is nothing to say}
}
}
答案1
我認為對按鍵的作用有輕微的誤解。處理/.is choice
程序定義一個選擇。所以你需要
\pgfkeys{/gtr/database/.cd,people=#1}%
“執行”樣式。然後國籍就被儲存了,\nationality
因為你在撥號時這麼說了
nationality/.store in=\nationality,
完整的例子。
\documentclass{article}
\begin{filecontents}[overwrite]{test_database.tex}
% Create database
% Jane Water
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/JaneID/.style={
female,
nationality = british,
given name = Jane,
family name = Water,
language = {English},
comment = {Something else}
}
}
% Justine Random
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/JustineID/.style={
female,
nationality = french,
given name = Justine,
language = {French, English},
% family name = Random,
comment = {Something interesting}
}
}
% Tom Water
\pgfkeys{/gtr/database/.cd,
people/.is choice,
people/TomID/.style={
male,
nationality = british,
given name = Tom,
family name = Water,
language = {English},
% comment = {There is nothing to say}
}
}
\end{filecontents}
\usepackage[all]{genealogytree}
\begin{document}
% Define new keys in genealogytree database
\pgfkeys{/gtr/database/.cd,
nationality/.store in=\nationality,
nationality=unknown,
given name/.store in=\givenname,
family name/.store in=\familyname,
language/.store in=\language
}
% Define new format for genealogytree
\gtrDeclareDatabaseFormat{xTestFormat}
{
% Define box title based on nationality
\ifdefined\nationality
\gtrset{box={title=\nationality}}
\fi
% Define tcolorbox parameters based on 'nationality' key
\tcbset{unknown/.style={colback=black!5!white,colframe=black}}
\tcbset{french/.style={colback=blue!5!white,colframe=blue}}
\tcbset{british/.style={colback=red!5!white,colframe=red}}
}
{ % Define informations to print in the box
\gtrPrintSex~\textcolor{blue}{\textbf{\givenname}}
\ifdefined\familyname
\familyname
\fi
\language
\gtrifcommentdefined{\gtrPrintComment}{}
}
\input{test_database}
% Create a command to print people complete data
\newcommand\PrintCompletePeople[1]{
This is the direct output: #1
I want to know what is behind the key:
\pgfkeys{/gtr/database/.cd,people=#1}%
\nationality
}
\begin{tikzpicture}
\genealogytree[
timeflow=down,
processing=database,
database format=xTestFormat,
box={\nationality}
]
{child[id=fam_Water]{
p[id=Justine]{people=JustineID}
g[id=Tom]{people=TomID}
c[id=Jane]{people=JaneID}
}
}
\end{tikzpicture}
\newpage
\PrintCompletePeople{JaneID}
\end{document}