1

Let's consider this simple example of a TikZ picture that defines the node distance and a style called mynode within the square brackets:

\begin{tikzpicture}[
  node distance=2.5em, auto,
  mynode/.style={draw=black, rectangle, minimuim size=2em},
]
\node[mynode] (name) {label};
\end{tikzpicture}

When create another TikZ picture within the same LaTeX document, I can copy the content between the square brackets to get the same style.

However, I have to update all figures separately to change the style. How can I define the content between the square brackets in a central place and use it in multiple TikZ figures?

8
  • 1
    You can use \tikzset{<options>} somewhere in a higher group to apply settings for that group, or you can set them in your preamble for global settings.
    – Max
    Sep 1 '18 at 12:34
  • 1
    @Max Thanks, that's very helpful. Is there a way to specifically include styles into pictures instead of making the styles available globally?
    – danijar
    Sep 1 '18 at 12:54
  • 1
    Well you could nest styles. An example: style a/.style={style b/.style={draw,minimum size=2em}}. Then if you if you call style a at the start of your tikzpicture like \begin{tikzpicture}[style a], it will make style b available for use. But if you don't call style a, it is not available.
    – Max
    Sep 1 '18 at 13:03
  • 1
    You can create say a header.tex file containing all styles then \input this file in the preamble of your figures if you precompile them as standalone document
    – BambOo
    Sep 1 '18 at 13:03
  • 1
    Similarly you could globally define style b, and let style a overwrite it locally. Then if you call style a for a certain picture, it uses the overwritten style b, and pictures without style a use the original style b.
    – Max
    Sep 1 '18 at 13:04

Browse other questions tagged or ask your own question.