![我正在尝试将命令数组传递给新命令或使用带有“includesvg”的“for”循环的定义](https://linux22.com/image/470474/%E6%88%91%E6%AD%A3%E5%9C%A8%E5%B0%9D%E8%AF%95%E5%B0%86%E5%91%BD%E4%BB%A4%E6%95%B0%E7%BB%84%E4%BC%A0%E9%80%92%E7%BB%99%E6%96%B0%E5%91%BD%E4%BB%A4%E6%88%96%E4%BD%BF%E7%94%A8%E5%B8%A6%E6%9C%89%E2%80%9Cincludesvg%E2%80%9D%E7%9A%84%E2%80%9Cfor%E2%80%9D%E5%BE%AA%E7%8E%AF%E7%9A%84%E5%AE%9A%E4%B9%89.png)
我从以下问题中学到了:
我试图将祖先列表作为数组与新命令或定义或新命令与定义作为数组传递到相同的新命令或相同的定义。
以下是小代码:
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{pgffor}
\usepackage{svg}
\usepackage[all]{genealogytree}
\newlength{\mypx}
\setlength{\mypx}{0.013889in}
\newcommand\Ancestries[1]
{
\def\ancestrieslist{#1}
\foreach \ancestry in \ancestrieslist
{
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/\ancestry.svg}\par
}
}
\begin{document}
\linespread{1.5}
\begin{tikzpicture}
\genealogytree
{
parent
{
g[id = 01, male, box = {title = Self}]
{
\textbf{Ancestries}\\
\Ancestries{argentina, brazil, italy, portugal, spain}\\
}
}
}
\end{tikzpicture}
\end{document}
我还尝试了另外两种方法:
\newcommand{\Ancestries}[1]
{
\foreach \x in {#1}
{%
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/\x.svg}\par%
}
}
\def\Ancestries#1
{%
\foreach \x in {#1}
{%
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/\x.svg}\par%
}
}
结果应如下所示:
\textbf{Ancestries}\\
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/argentina.svg}
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/brazil.svg}
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/italy.svg}
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/portugal.svg}
\includesvg[width={10\mypx}]{assets/images/flags/twemoji/spain.svg}
这里的小日志:
No file minha-genealogia-completa-01.aux.
(/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd) (|'inkscape' -V ) (./svg-inkscape/argentina_svg-tex.pdf_tex) (./svg-inkscape/brazil_svg-tex.pdf_tex) (./svg-inkscape/italy_svg-tex.pdf_tex) (./svg-inkscape/portugal_svg-tex.pdf_tex) (./svg-inkscape/spain_svg-tex.pdf_tex)
/home/Ooo/minha-genealogia-completa-01.tex:113: LaTeX Error: There's no line here to end.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.113 ^^I^^I}
No pages of output.
答案1
错误
LaTeX Error: There's no line here to end.
通常在垂直模式下使用时会抛出\\
。在您的情况下,这是由\\
之后引起的\Ancestries{argentina, brazil, italy, portugal, spain}
,因为在每个条目之后\Ancestries
您都放置了一个\par
,因此这实际上会导致\par\\
,然后您就会收到该错误。
编译结果如下:
\documentclass{standalone}
\usepackage{graphicx}
\usepackage{pgffor}
\usepackage{svg}
\usepackage[all]{genealogytree}
\newlength{\mypx}
\setlength{\mypx}{0.013889in}
\newcommand\Ancestries[1]
{%
\foreach \ancestry in {#1}%
{%
\rule{10\mypx}{10\mypx}\par
%\includesvg[width={10\mypx}]{assets/images/flags/twemoji/\ancestry.svg}\par
}%
}
\begin{document}
\linespread{1.5}
\begin{tikzpicture}
\genealogytree
{
parent
{
g[id = 01, male, box = {title = Self}]
{
\textbf{Ancestries}\\
\Ancestries{argentina, brazil, italy, portugal, spain}
}
}
}
\end{tikzpicture}
\end{document}