68

I proposed in chat that we put together a "Best of TikZ on TeX-SX" package. There have been some really neat answers to problems developed on the site, and I think it would be nice to put them together in to some sort of easily usable state. My reasons are:

  1. It's easier to download a single package/style file than to cut and paste a load of code from here, there, and everywhere into ones preamble.
  2. Some of the code could do with a bit of polishing (for example, putting in to a macro, hiding internal bits) that are standard when making a package, but not when posting an answer here.
  3. Publicity: Ideally, these would get used and the people who used them would find out about us.

By doing this as a collective venture, I hope that:

  1. It is a real community project. I'm not so naive that I think that loads of people will do the necessary work, but hopefully lots of people will see what's going on and at least feel as though it's based on the community's collective work.
  2. It isn't loads of work for any one person. Most of the stuff I'm thinking of is already workable, so I'm hoping it won't take too much work to put it together.
  3. This is only the first of many ...

On that last note, I'm picking TikZ because it's the area I think I've contributed most to. Also, there's a reasonable volume of TikZ answers here to choose from, and a good number of people contributing them.

First Steps: We need some code to put in the package, and some volunteers willing to take part. I think that we can adapt the SE software to gather all that information here! So:

  1. If you like or dislike the idea, vote on this question accordingly.
  2. Propose (and link to) TikZ/PGF answers on the main site that you would like to see in such a package in answers to this question, one link per answer. Also vote for those you like (but the people who volunteer to put it together will have the final say). Please bear in mind that to be worth putting in a package, it has to be something that you can envision being used several times. Proposing your own answers is not only acceptable but actively encouraged. If, when reading an answer, something occurs to you as a possible improvement, please make a note of it (just the idea at this stage).
  3. In one answer, we can collect names of volunteers who are willing to do a bit of extra work polishing the answers. I'll start this off, make it CW, and "accept" it (when I can) to ensure that it is easily distinguished from the rest.

Template for proposals

### TikZ/PGF Answer:

### Brief Description:

### Possible Improvements:

Further discussion on this topic is available here:

TikZ/PGF answer package, Part 2

13
  • 3
    this is great! let us know if there's anything the community team can do to assist. Commented Apr 1, 2011 at 8:56
  • @Andrew: Your acceptance won't make it stay on top; that doesn't work for self-accepts. Commented Apr 1, 2011 at 8:56
  • @Hendrik: Didn't know that! Nonetheless, the important thing is to distinguish the volunteers answer from the rest and "accepting" it will at least do that. Commented Apr 1, 2011 at 9:19
  • @Hendrik: I've edited accordingly. Commented Apr 1, 2011 at 9:20
  • @Andrew: Do you want me to make the answer or the whole thread a CW? Commented Apr 1, 2011 at 9:51
  • @Martin: Whoops! I forgot to make that answer CW (done). As for the whole thread, I don't see any advantage in it being CW, but I don't see any disadvantage either. Commented Apr 1, 2011 at 10:03
  • @Martin: On second thoughts, I thought of a use for CW mode so, yes please hit it with Mjolnir. Commented Apr 1, 2011 at 10:10
  • 1
    I also have some other TikZ solutions I was planning to publish as part of a bundle. They are no questions here on TeX.SX which ask about it (yet) (but with great foresight I already coded them ;-) ). One would add more anchors to existing standard node shapes like rectangle, like east north east, for points at 25% and 75% of the height and width. Commented Apr 1, 2011 at 11:05
  • @Martin: If you're pondering including them in this, I'd say that that was fine. So long as the majority come from TeX-SX then I think that adding a few extra is fine. You could always tell me what they are and I'll ask a question for you! Commented Apr 1, 2011 at 11:22
  • @Martin: I definitely want to see your idea about the extra nodes for standard shapes, I needed something exactly like that earlier today and ended up using coordinate calculations. tex.stackexchange.com/questions/14769/…
    – Jake
    Commented Apr 1, 2011 at 21:04
  • 1
    this is an interesting project. in my opinion, it could use a manual (which i will volunteer to proofread). and when it's done, i would like to solicit an overview article for tugboat. Commented Sep 14, 2011 at 14:34
  • @barbara: Thanks for your support and offer of help. At the moment, the project is proceeding in more of a piecemeal way than as one huge project (in particular, I don't think we'll ever declare it "done"!). The first "package" is already on CTAN (braids) and I have a couple of others that just need polishing. Other things keep getting in the way! Commented Sep 14, 2011 at 17:45
  • 2
    @Andrew -- even if it's piecemeal, there will probably come a time when it reaches a critical mass. i'd like to reiterate my suggestion to present it, when it reaches that point, in a tugboat article. although i recognize a lot of tugboat readers among the members of tex.sx, there's still likely to be a residue that haven't yet found there way here. some free publicity wouldn't hurt. Commented Sep 16, 2011 at 15:15

39 Answers 39

8

Volunteers

3
  • I would volunteer, but I don't think I'd be any use. I can offer to test the package, though...
    – Seamus
    Commented Apr 6, 2011 at 12:29
  • Same here. I don't have any experience with making packages, but I would like to help with testing and documentation, if required.
    – Jake
    Commented Apr 7, 2011 at 18:23
  • @Jake: Neither do I (except small trivial packages), but you do have good knowledge of TikZ/PGF. chat.stackexchange.com/rooms/409/from-answers-to-packages
    – Caramdir
    Commented Apr 7, 2011 at 18:29
31

TikZ/PGF Answer:

Caramdir's answer and Jake's addition to Drawing on an image with TikZ

Brief Description:

Allows the drawing of TikZ code over an included image.

Possible improvements:

  • Adding some options to adjust the grid and the labels (maybe in combination with my other suggestion). Including a global option to switch off all grids.

  • Could also be done as PGF-only variant

Improved code

I (Caramdir) encapsulated the idea into environments: https://gist.github.com/899107. Currently there is no option for grids, as Martin's grid code has no option to change the step size of the grid (a grid with lines at all integers is not very useful in this setting).

1
  • It may be useful to add some key-value driven interface for common highlighting features. See the simpleslides module (page 29-35) for some examples.
    – Aditya
    Commented May 31, 2011 at 2:58
22

TikZ/PGF Answer

There are a variety of ways to use TikZ to add annotations to regular tables using the [remember picture] method. Here are some:

Highlighting table cells

How to draw lines around multiple table cells

How to format table with long column head entries

Brief Description

We tend to think of TiKZ as a method for making drawings, but it also can be used effectively to add annotations to regular LaTeX environments. One especially useful use of it is to add annotations to tables, such as arrows pointing to cells or geometric shapes around cells.

Highlighting table cells

How to draw lines around multiple table cells

How to format table with long column head entries

4
  • I think this and the tikzmark trick in the solution about adding braces to text share a lot of features, maybe we should merge these answers?
    – Seamus
    Commented Apr 6, 2011 at 12:30
  • I am referring to this one
    – Seamus
    Commented Apr 6, 2011 at 12:31
  • @Seamus That's not a bad idea. Shall I do that? Others' comments?
    – Alan Munn
    Commented Apr 7, 2011 at 1:35
  • I think that the answer I linked to doesn't have much to it apart from using the [remember picture] thing to add stuff. So maybe add those answers to this question and then we can delete the other one?
    – Seamus
    Commented Apr 7, 2011 at 7:59
20

TikZ/PGF Answer:

Stroke with variable thickness

Brief Description:

Making variable width lines.

variable width line

Possible Improvements:

Connecting this with the Changing colour halfway along path

20

Tikz/PGF Answer:

How to create magnified subfigures and corresponding boxes for portions of a large image

Brief Description

A method for magnifying rectangular sections of an image, displaying rectangles on top of the image to show which portions are magnified, and arranging the magnified portions in an aesthetically pleasing manner as a subcaptionbox.

Options for displaying a grid over the original image to ease placing the magnifications, using coloured frames to link the magnified portions to their position on the original image, or using different black and white dash patterns for better visibility in grayscale printouts.

enter image description here

Possible Improvements

19

TikZ/PGF Answer:

Drawing Mechanical Systems in LaTeX

Brief Description:

Easily drawing draw masses, springs, dampers and grounds.

enter image description here

15

TikZ/PGF Answer:

Changing the colour of a path half way along

Brief description

Changes the colour of a path halfway along. Useful for very thick lines so that the colour changes at the bend in a consistent way.

split colour paths

Possible improvements

Needs turning into a macro and needs stress-testing. It works by clipping, so we need to make sure that it doesn't do weird things for tight angles, more complex paths and the like.

Status

Switched to the arrowhead version.

  • Code: Implemented
  • Files: tikzcolourpath.tex
  • Testing: None
  • Documentation: None
15

Tikz/PGF Answer:

Need help creating a 3D cube from a 2D set of nodes in TikZ

Brief Description

Macro for drawing cuboids with grids, with options for rotating and shading.

enter image description here

15

TikZ/PGF Answer:

Chinese checkers board using TikZ

Brief Description:

Draws a Chinese checkers board. Indicates moves.

enter image description here

Possible Improvements:

Include board designs for other similar games.

15

TikZ/PGF Answer:

Sieve of Eratosthenes in tikz

Brief Description:

Showing how to find prime numbers by successively eliminating multiples.

enter image description here

enter image description here

14

TikZ/PGF Answer:

Is there the easiest way to toggle (show/hide) navigational grids in TikZ?

Brief Description:

Creates a show grid=<options> key which draws a grid with configurable labels:

This is quite useful in the creation phase of the picture.

Possible Improvements:

Could be converted to PGF-only code to make it also usable for pgfpictures. Add an option to modify the distance between the lines.

14

TikZ/PGF Answer:

OK this isn't so much one answer as a bunch of answers on these questions about braces:

Brief description

The actual functionality could be "arbitrary braces" or just macro-ifying Andrew's tikzmark thing. (Which might be useful more generally).

Large braces over several items in an itemize with text by the brace

Adding a large brace next to a body of text

1
14

TikZ/PGF Answer:

Cool Text Highlighting in LaTeX

Brief Description:

Highlighting text as if it were done with a text marker.

enter image description here

12

TikZ/PGF Answer:

Tikz triangle with point colours

Brief Description:

Three different solutions to drawing an “RGB triangle”. Each has its own advantages/disadvantages, so I'd add all three of them.

rgb triangle

Possible Improvements:

Make the solutions accept arbitrary color.

12

Tikz/PGF Answer:

How can I invert a 'clip' selection within TikZ?

Brief Description

A method whereby one can specify the inverse of the usual clipping method.

enter image description here

12

TikZ/PGF Answer:

How to make nice braids diagrams

Brief Description:

Draw braid diagrams based on just specifying the crossings, as was done in a Metapost module by Stijn Symens.

Andrew's package shows off some PGF techniques quite nicely, so the source is well worth reading.

enter image description here

Blog post

The Braids Package

Requested features, implemented:

Matsaya suggested some features beyond those in Andrew's original implementation, each of which has been implemented:

  1. the possibility to draw horizontal braids – the braid options allow PGF transformations on the output;
  2. the possibilities to draw the "floors" – the new vertical bar syntax allows this;
  3. possibilities to have 2 (or more) nodes on the same floor (not really necessary) – the new syntax is to connect them with hyphens;
  4. to color a group of floor – PGF styling options can now be passed for floors, both individually and collectively;
  5. individually choose the decoration (color, etc) of each "string" – Likewise for strands;
  6. possibility to label the top or bottom of string (individually) – Strands are labelled according to their positions, both at top and bottom.

Additionally, Charles noted that the original syntax for expressing crossings was not as compact as Stijn Symens' Metapost package. Andrew implemented a new syntax of the form s_1 s_2^{-1} s_3, where the s isn't significant and can be anything that isn't "special".

Status

  • Code: Implemented
  • Tests: None
  • Files: braids.dtx, braids_test.tex
  • Documentation: Written
4
  • Just to note that the latest version of the braids "package" already implements many of these improvements. Commented May 26, 2011 at 12:50
  • @Andrew: Great. Please edit. BTW, did you know that answering my "challenge" and being 2nd to get the tikz-pgf tag badge officially makes you a PGF guru? Commented May 26, 2011 at 12:54
  • Edited as requested. I'll have to make a "PGF Guru" sign for my office door. Commented May 26, 2011 at 20:51
  • Phew. That was the hardest one yet. Had to add 14 characters to the code. Right, that's the lot on this one ... so far! Commented Jun 3, 2011 at 19:16
12

TikZ/PGF Answer:

How to define a figure size so that it consumes the rest of a page?
as well as
Stretching a framebox over the whole page

Brief Description:

Provides a special text area node which allows the drawing/placing of elements on the page.

enter image description here

Possible improvements:

Some macros and/or environments based on this could be added, e.g. one which allows the inclusion of a box/image which fills the rest of the page. More specialized ones which generate a non-floating figure and table or custom (now pseudo-)float environment.

Also some special nodes for the header, footer and marginpar should be added. This would allow to easily draw material into this areas.

These solutions use TikZ/PGF but actually don't draw nothing.

11

TikZ/PGF Answer:

How to draw triangular grid in TikZ?

Brief Description:

Drawing a grid of triangles. Not very impressive but potentially useful and strangely absent from TikZ.

enter image description here

Possible Improvements:

Non-equilateral triangles. Hexagonal grid.

11

TikZ/PGF Answer:

Can I have framed blocks in beamer?

Brief Description:

Have beamer block environments appear framed, rather than filled with a background colour.

OK, so it's not really TikZ, but it does involve some low level PGF hacking and it's a nice addition to beamer.

enter image description here

Possible Improvements:

Non-rounded version, thicker lines...

1
  • tcolorbox is surely a good fit for this
    – Carel
    Commented Jan 1, 2017 at 8:46
10

TikZ/PGF Answer:

Multiple equation numbers for a tikz picture

Brief Description:

Using TikZ is often a useful way of getting the pieces right in a complicated mathematical diagram. If there's only one diagram, it's easy to label it by putting it in a suitable mathematics environment (equation, for example). But if there are several diagrams, and it's not desirable to split them up (mutual alignment, for example), then it would be useful to be able to label the pieces individually.

enter image description here

Possible Improvements:

  • Shift the actual placement of the equation numbers in to a execute at end of picture routine to ensure that the bounding box used is the actual bounding box of the picture (and not a half-way stage).
  • Allow for customisation as to labels on the left and right.
  • Allow for customisation of label style (parentheses and so forth).

Status:

  • Code: Implemented
  • Files: tikzeqnos.tex
  • Testing: None
  • Documentation: None
1
  • This is similar to what Joseph Wright's chemscheme does, isn't it?
    – Seamus
    Commented Apr 1, 2011 at 11:11
9

Tikz/PGF Answer:

How can I set the background color of the rows and columns of a matrix node in Tikz?

Brief Description

After setting up a matrix using TikZ, this puts nodes in each cell of the right size so that they tile the matrix. This can be used to, for example, colour the matrix with no gaps between the cells.

enter image description here

Status

  • Code: Implemented
  • Tests: None
  • Files: matrixcells.dtx, matrixcells_test.tex
  • Documentation: Written
9

TikZ/PGF Answer:

Drawing a circle on a non xy-plane with TikZ

Brief Description:

Drawing perspectively correct circles on non-xy planes without worrying about the actual transformation.

enter image description here

8

TikZ/PGF Answer:

Applying a postaction to every path in TikZ

Brief Description:

Solves the problem of postactions being recursively applied in a scope. Very short code, but can be rather handy.

2
8

TikZ/PGF Answer:

Add more anchors to standard TikZ nodes

Brief Description:

Adds anchors like north north east or west south west to the TikZ rectangle shape to augment the standard nodes.

Possible Improvements:

Do the same for the circle shape.

Status

  • Code: Implemented for the rectangle shape.
  • Tests: None
  • Files: pgflibraryshapes.tex-sx.dtx
  • Documentation: Partially written
7

TikZ/PGF Answer:

Drawing a tree of grids

Brief Description:

Adds a rectangular node with a grid inside and some additional anchors.

enter image description here

Status

  • Code: Implemented
  • Tests: None
  • Files: pgflibraryshapes.tex-sx.dtx
  • Documentation: None
3
  • This definitely needs to go in. I'd like to see mid and base anchors for the grid cells as well, but I haven't been able to add them myself (I find all those \noexpands really intimidating...)
    – Jake
    Commented Apr 12, 2011 at 17:52
  • @Jake: Yes the \noexpands are annoying. Since there are no text nodes at the moment, I don't really know where to put mid and base. It might be useful to rewrite this as a multipart node.
    – Caramdir
    Commented Apr 12, 2011 at 18:51
  • 1
    This is now in pgflibraryshapes.tex-sx (without mid and base)
    – Caramdir
    Commented Jun 23, 2011 at 20:17
7

TikZ/PGF Answer:

Mexican hat in TikZ

Brief Description:

Draws a mexican hat.

enter image description here

Possible Improvements:

The lower part of the brim can be improved.

2
  • 6
    I don't think this is the sort of thing that needs doing often enough that it needs putting in a package.
    – Seamus
    Commented Apr 15, 2011 at 11:40
  • 1
    I'm going to give this a +1 because it is a neat example of the arc and sin path construction methods which I have never really paid attention to before.
    – Sharpie
    Commented Apr 19, 2011 at 4:00
7

TikZ/PGF Answer:

Putting a timeline for dates in moderncv

Brief Description:

Adding progressbar-like timelines to your CV. Available as a package: moderntimeline

enter image description here

7

TikZ/PGF Answer:

Modify TikZ coil decoration

Brief Description:

Separates the coil decoration in two - one that goes up and an other that goes down. This can be used to draw coils that wraps around e.g a cylinder.

coil wrap

Possible Improvements:

I think that TikZ would benefit from a highlevel way to modify existing decorations.

7

TikZ/PGF Answer:

https://tex.stackexchange.com/a/47394/86

The shape is finished by Altermundus and zeroth in the following answer :

https://tex.stackexchange.com/a/47484/3235

Brief Description:

Draw a Batman logo in TikZ.

Possible Improvements:

  1. Make it into a node shape, with customisable colours, text inset into the bat, and anchors galore.
  2. Add logos of other superheros (bonus points for bananaman, supergran, and supertex)
2
  • Adding shiny glass-like effect may be interesting, see the example tex.stackexchange.com/q/47273/9467 Commented Mar 9, 2012 at 15:13
  • For the interested, it is still under construction to make it an explicit .sty file with additional goodies.
    – percusse
    Commented Mar 19, 2012 at 11:38
6

Brief Description:

How can we display fireworks?

Possible Improvements:

Drawing fireworks explosions.

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .