In this specific case you can use anchor=center
to restore the default positioning. The right
etc. settings modify the used anchor.
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
% wanted: square centered on line
\begin{tikzpicture}
\draw (0,0) -- (0,1);
\node[fill] at (0,.5) {};
\end{tikzpicture}
% got: square to the right of line
\begin{tikzpicture}[red]
\node[fill] (O) {};
\node[right=of O] {% <- this 'right of' is inherited; how to avoid?
\begin{tikzpicture}[anchor=center]
\draw (0,0) -- (0,1);
\node[fill] at (0,.5) {};
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}
In the general case if you want to avoid any settings to affect the sub-tikzpicture
I would store it into a savebox before the main tikzpicture
and insert that box:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
% wanted: square centered on line
\begin{tikzpicture}
\draw (0,0) -- (0,1);
\node[fill] at (0,.5) {};
\end{tikzpicture}
\newsavebox\mybox
\begin{lrbox}{\mybox}
\begin{tikzpicture}
\draw (0,0) -- (0,1);
\node[fill] at (0,.5) {};
\end{tikzpicture}
\end{lrbox}
% got: square to the right of line
\begin{tikzpicture}[red]
\node[fill] (O) {};
\node[right=of O] {% <- this 'right of' is inherited; how to avoid?
\usebox\mybox
};
\end{tikzpicture}
\end{document}
Best Answer
Just put:
in your preamble, and you'll be able to use
stylename
andanothetstyle
in all thetikzpicture
s of your document.