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.

I just learned that you can use braces to scope the effect of \tikzset. But it is not allowed in align environments:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
    \begin{align}
        \tikzset{every node/.style={draw}}
        \tikz{\node {};} &= \text{Box}\\
        {
            \tikzset{every node/.style={fill}}
            \tikz{\node {};} &= \text{Filled box}\\
        }
        \tikz{\node {};} &= \text{Box}\\
        \tikz{\node {};} &= \text{Box}
    \end{align}
\end{document}

This fails with a lot of errors like "Misplaced alignment tab character" and others.

Sadly, even a workaround doesn't work here:

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
    \begin{align}
        \tikzset{every node/.style={draw}}
        \tikz{\node {};} &= \text{Box}\\
        \tikzset{every node/.style={fill}}
        \tikz{\node {};} &= \text{Filled box}\\
        \tikzset{every node/.style={draw}}
        \tikz{\node {};} &= \text{Box}\\
        \tikz{\node {};} &= \text{Box}
    \end{align}
\end{document}

enter image description here

Notice how the last node is not drawn. What's going wrong?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

Anyhow, the &'s already limit the scopes. Hence, even removing the stand alone two braces from the OP MWE, the last two boxes are not drawn. Possible simple work-around:

either

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
        \begin{align}
        \tikzset{every node/.style={draw}}
        \tikz{\node {};} &= \text{Box}\\
            \tikzset{every node/.style={fill}}
            \tikz{\node {};} &= \text{Filled box}\\
        \tikzset{every node/.style={draw}}\tikz{\node {};} &= \text{Box}\\
        \tikzset{every node/.style={draw}}\tikz{\node {};} &= \text{Box}
    \end{align}
\end{document}

or

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\begin{document}
\tikzset{every node/.style={draw}}
        \begin{align}
        \tikz{\node {};} &= \text{Box}\\
        \tikzset{every node/.style={fill}}
            \tikz{\node {};} &= \text{Filled box}\\
        \tikz{\node {};} &= \text{Box}\\
        \tikz{\node {};} &= \text{Box}
    \end{align}
\end{document}

Both produce boxes aligned

share|improve this answer
    
setting the \tikzset{every node/.style={draw}} globally, before the \align and overwriting just the one that's different is nice. +1 –  barbara beeton Mar 27 at 18:50
add comment

within an align environment -- or any environment where cells are separated by & or \\ -- every cell is totally independent of every other. thus instructions for setting or changing styles must be complete within each cell.

you can "rescue" your workaround example by inserting the code

\tikzset{every node/.style={draw}}

immediately after the last \\.

share|improve this answer
add comment

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.