ifthen + [ngerman]babel + pgfplots + axis + 文本高度 = ☇

ifthen + [ngerman]babel + pgfplots + axis + 文本高度 = ☇

继续[ngerman]babel + pgfplots + axis + 文本高度 = ☇和喂养

\RequirePackage{ifthen}
\newboolean{techrep}
\setboolean{techrep}{true}
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\ifthenelse{\boolean{techrep}}{%
  \begin{tikzpicture}\shorthandoff{"}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
}{}
\end{document}

(在真实的例子中,会有很多不相关的代码,这里都抽象出来了)到pdflatex,我们得到

! Missing number, treated as zero.
<to be read again> 
                   p
l.22 }{}

? X

谁是罪魁祸首?该怎么办?使用 TikZ 库babel没有帮助,\shorthandoff(")在各个地方插入也没有帮助(尽管我还没有测试过所有地方)。

答案1

这个帖子是相关的。据我所知,那里的答案只提供了解决方法。这是另一种解决方法。

\RequirePackage{ifthen}
\documentclass{article}
\newboolean{techrep}
\setboolean{techrep}{true}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\begingroup\shorthandoff{"}
\ifthenelse{\boolean{techrep}}{%
  \begin{tikzpicture}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
}{}\endgroup
\end{document}

我认为不使用该ifthen包可能是最佳解决方案。如果您加载pgf,则可以随时引入测试整数并使用\ifnum\ifcase或a \newif

\documentclass{article}
\newif\iftechrep
\techreptrue
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}
\begin{document}
\section{Section name}
\iftechrep
  \begin{tikzpicture}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
\else  
\fi
\end{document}

答案2

您可以在本地定义 active"来执行 Ti 所期望的操作Z:

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{ifthen}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}

\newboolean{techrep}
\setboolean{techrep}{true}

\begin{document}
\section{Section name}
\ifthenelse{\boolean{techrep}}{%
  \begin{tikzpicture}\edef"{\string"}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
}{}
  \begin{tikzpicture}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
\end{document}

我把图片设置了两倍以便进行比较。

在此处输入图片描述

\newboolean{techrep}然而,您可以利用与本质上相同的事实\newif\iftechrep

\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{ifthen}
\usepackage{pgfplots}\pgfplotsset{compat=1.14}
\usetikzlibrary{babel}

\newboolean{techrep}
\setboolean{techrep}{true}

\begin{document}
\section{Section name}
\iftechrep
  \begin{tikzpicture}
    \begin{axis}[
      xmax         = 5.5,
      xmin         = 0,
      ymax         = 5.5,
      ymin         = 0,
      extra x tick style = {text height=height("0")},
      extra x ticks = 3
      ]
    \end{axis}
  \end{tikzpicture}%
\fi
\end{document}

相关内容