有人能提供一个 tikz 中复合数学语句的例子吗?我发现大多数答案都很难理解或缺乏。我想要一个像这样的 MWE 示例(注意,这个示例确实如此不是編輯
\documentclass[landscape]{article}
\usepackage{tikz}
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\newcommand{\tableXOff}{0.4}
\newcommand{\tableXPad}{\tableXOff}
\newcommand{\tableYOff}{0.1}
\newcommand{\tableYPad}{\tableYOff}
\newcommand{\tableW}{0.5}
\newcommand{\tableH}{0.2}
\newcommand{\xShift}{2}
\usepackage[top=1in,bottom=1in,right=1in,left=1in]{geometry}
\begin{document}
\begin{tikzpicture}[scale=5.3,cap=round,>=latex]
\draw[blue,ultra thick] (-2cm,-2cm) rectangle (2cm,2cm);
\foreach \x in {0,1,...,3} {%
\fill[brown] (\x*(\tableXPad+\tableW)+\tableXOff-\xShift,-\tableYOff) rectangle (\x*0.9+\tableXOff+\tableW-\xShift,-\tableYOff-\tableH);
}
\end{tikzpicture}
\end{document}
因此,我不会盲目地尝试读取值,而是使用变量。不幸的是,周围的括号(\tableXPad+\tableW)
会导致错误。我该如何解决这个问题?
答案1
将包含有问题的括号的有序对中的条目放在括号内:
\documentclass[margin=10pt,convert]{standalone}
\usepackage{tikz}
\newcommand{\tableXOff}{0.4}
\newcommand{\tableXPad}{\tableXOff}
\newcommand{\tableYOff}{0.1}
\newcommand{\tableYPad}{\tableYOff}
\newcommand{\tableW}{0.5}
\newcommand{\tableH}{0.2}
\newcommand{\xShift}{2}
\usepackage[top=1in,bottom=1in,right=1in,left=1in]{geometry}
\begin{document}
\begin{tikzpicture}[scale=5.3,cap=round,>=latex]
\draw[blue,ultra thick] (-2cm,-2cm) rectangle (2cm,2cm);
\foreach \x in {0,1,...,3} {%
\fill[brown] ({\x*(\tableXPad+\tableW)+\tableXOff-\xShift},-\tableYOff) rectangle (\x*0.9+\tableXOff+\tableW-\xShift,-\tableYOff-\tableH);
}
\end{tikzpicture}
\end{document}
结果: