Graphics, Figures & TablestikZ | Style Definitions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

tikZ | Style Definitions

Post by psionman »

I am creating many similar figures in a document and I wondered if it is possible to have a global definitions of tikz styles (e.g.UnitVector in the example below) that I can define at document level, but use in many figures in the document?

Code: Select all

\begin{figure}[ht]
\begin {center}
\begin{tikzpicture}
[UnitVector/.style={ultra thick,->},
force line/.style={very thick,->},
dashed line/.style={dashed, thin},
]

%vector 
\coordinate (VectorBase) at (-2,2);
\draw[UnitVector] (VectorBase) -- +(1,0) node[above] {$\mathbf{i}$};
\draw[UnitVector] (VectorBase) -- +(0,1) node[right] {$\mathbf{j}$};
\draw[UnitVector] (VectorBase) -- +(-0.5,-0.5) node[right] {$\mathbf{k}$};

%Particle
\filldraw (0,0) circle (2pt);
\draw[force line] (0,0) -- (0,-1) node[right]{$\mathbf{W}$};
\draw[force line] (0,0) -- (-1,1) node[left]{$\mathbf{T}$};
\draw[force line] (0,0) -- (0,1) node[right]{$\mathbf{F}$};
\draw[force line] (0,0) -- (1,0) node[right]{$\mathbf{N}$};
\draw (0,0.4) arc (0:180:0.2);
\draw (2,1)[->]node[anchor=south west]{$\arctan\tfrac{4}{3}$}--(-0.2,0.3);

\end{tikzpicture}
\caption{Force diagram for cylinder.}
\label{F:ForceDiagramCylinder}
\end{center}
\end{figure}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Style Definitions

Post by Stefan Kottwitz »

Hi,

you can use \tikzstyle for defining global styles:

Code: Select all

\tikzstyle{UnitVector} = [ultra thick,->]
\tikzstyle{force line} = [very thick,->]
\tikzstyle{dashed line} = [dashed, thin]
Stefan
LaTeX.org admin
psionman
Posts: 30
Joined: Thu Nov 10, 2011 3:33 pm

Re: tikZ | Style Definitions

Post by psionman »

Thanks Stefan
User avatar
Stefan Kottwitz
Site Admin
Posts: 10350
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Style Definitions

Post by Stefan Kottwitz »

By the way, I would use \centering inside figure environments. The reason is, that \begin{center} ... \end{center} causes additional vertical space, which is useful within normal text, but within figure the figure environment itself already brings space around.

Stefan
LaTeX.org admin
Post Reply