我正在尝试将命令数组传递给新命令或使用带有“includesvg”的“for”循环的定义

我正在尝试将命令数组传递给新命令或使用带有“includesvg”的“for”循环的定义

我从以下问题中学到了:

我试图将祖先列表作为数组与新命令或定义或新命令与定义作为数组传递到相同的新命令或相同的定义。

以下是小代码:

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

相关内容