[Tex/LaTex] What should be included in “good practices” for Tikz 101

beamertikz-pgf

I have been making graphics (mostly flow graphs) for my presentations, lately, using Powerpoint and most recently LucidChart. I kind of avoided using Latex for this purpose as I had a feeling that its not going to be easy. Anyways, now I have decided to learn and master this powerful tool but going through the manual ,as I expected, is not a good idea for a jump start.
So I was wondering if I can get some good advices that I should flow while making graphics in my beamer presentations. One thing that I have noticed that one needs to specify coordinates for everything. Is it a good idea to first draw a grid on slide and then proceed?

So please contribute practices that you have found to be useful for generating graphics using tikz package. I am looking forward to hear what experts have to say in this regard

Best Answer

  • Use styles. Whenever you have color, shape, fonts, alignment, define a TikZ style for it and use it. Don't apply such formatting details to nodes or edges, apply the style. A single point for consistent customizing.

  • Inherit styles. Start with a base node style (font family, base color), define styles which use base styles and add size or color or alignment - no repetitions, single points for global changes.

  • Use macros. Have consistent TikZ commands or command sequences, which can be reused and changed.

  • Use constants. For every value needed, such as distances, declare a constant via \def or a TikZ length command, so you can use it repeatedly and adjust it at a single source code position to customize a whole drawing or a lot of drawings.

  • Use relative positions. So you can change a reference coordinate, and all other positions will be automatically adjusted.

  • Let TikZ calculate for you. Once certain points such as corners are defined, use TikZ syntax to define a relative positions such as middle points and intersection points. Let TikZ do the geometry for you. If you change the reference points or image size, all will automatically adjust.

  • Name everything. Especially in non-trivial drawings, edges between named coordinates are much clearer to read than using coordinate numbers everywhere.

  • Use scopes. Don't repeat things - if you cannot apply a bunch of properties via styles, use a scope to apply settings to a whole area of a drawing. Also here, it's easy to change that part at a single position.

  • Use loops. If you need to repeat things, benefit from the power of TikZ \foreach loops to reduce the amount of repeated code.

  • Don't nest TikZ pictures. There is always another way to do it.