Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Could someone provide an example of a complex compound mathematical statement in tikz as I find that most of the answers out there are difficult to understand or lacking. I want a MWE example like this one (note, this one does not compile)

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

So I don't go blind trying to read values, but instead use variables. Unfortunately, the parantheses around (\tableXPad+\tableW) cause an error. How do I get around this?

share|improve this question
    
Put braces around (I think) the first entry in the problematic ordered pair. –  Charles Staats Apr 11 at 5:00
    
@CharlesStaats please include an answer with an example as the very first thing I did was bullet riddle the statement with curly brackets –  puk Apr 11 at 5:02

1 Answer 1

Put braces around the entry in the ordered pair that contains the problematic parentheses:

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

The result:

enter image description here

share|improve this answer
    
Sorry. I didn't see your answer when I posted mine. –  A.Ellett Apr 11 at 5:10
    
Actually, I think our posted answers were essentially simultaneous. –  Charles Staats Apr 11 at 5:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.