Tikz 和 babel 错误

Tikz 和 babel 错误

这段代码可以正常工作:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}
\begin{document}

\begin{tikzpicture}
  \tikzset{
    every picture/.prefix style={
      execute at begin picture=\shorthandoff{;}
    }
  }
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}

但是当我添加

\usepackage[utf8]{inputenc}
\usepackage[german]{babel}

到了序言部分,它开始给出错误:

! Argument of \language@active@arg" has an extra }.
<inserted text> 
                \par 
l.25 }

俄语也一样。它与数组中的引号有某种关联:

\def\names{{"1", "2"}}

我尝试了这里为法国人展示的技巧,但它们不起作用。

答案1

法语的诀窍是禁用简写;,德语不使用简写,而德语中要禁用的简写是"

然而,\tikzset{every picture/...}应该发出命令外部图片,否则不会有效果。

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{positioning,calc}

\tikzset{
  every picture/.prefix style={
    execute at begin picture=\shorthandoff{"}
  }
}

\begin{document}

\begin{tikzpicture}
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}

答案2

\usetikzlibrary{babel}在这种情况下有助于支持主动报价:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{babel,positioning,calc}
\begin{document}

\begin{tikzpicture}
  \tikzset{
    every picture/.prefix style={
      execute at begin picture=\shorthandoff{;}
    }
  }  
  \def\names{{"1", "2"}}
  \foreach \i in {0,1} {%
    \ifnum\i=0\relax
      \node (\i) [draw] {\pgfmathparse{\names[\i]}\pgfmathresult};
    \else
      \pgfmathparse{int(\i-1)}
      \node (\i) [draw,right= 1cm of \pgfmathresult]
            {\pgfmathparse{\names[\i]}\pgfmathresult};
      \draw[dotted] ($(\pgfmathresult.south east) !.5! (\i.south west)$)
            -- +(0,1cm);
  \fi
}
\end{tikzpicture}
\end{document}

结果

相关内容