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?

danijar
  • 1,005
  • 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 01 '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 01 '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 01 '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 01 '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 01 '18 at 13:04
  • 1
    @Max That's exactly what I was looking for. Would you mind writing this out as an answer below so I can accept it? – danijar Sep 01 '18 at 13:17
  • @danijar You could ask a new question that is more specific to what you would want to achieve. Something like "How to locally install Tikz styles that can be changed globally?". This would also attract more users so possibly more and better answers. It may seem tedious to ask a new question, but for future reference it is better to have a title that corresponds to what you want. – Max Sep 01 '18 at 14:50
  • @Max Makes sense. Here is the new question: https://tex.stackexchange.com/q/448897/61219 – danijar Sep 01 '18 at 19:00

0 Answers0