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

  • 3
    this is great! let us know if there's anything the community team can do to assist. – Jeff Atwood Apr 1 '11 at 8:56
  • @Andrew: Your acceptance won't make it stay on top; that doesn't work for self-accepts. – Hendrik Vogt Apr 1 '11 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. – Loop Space Apr 1 '11 at 9:19
  • @Hendrik: I've edited accordingly. – Loop Space Apr 1 '11 at 9:20
  • @Andrew: Do you want me to make the answer or the whole thread a CW? – Martin Scharrer Apr 1 '11 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. – Loop Space Apr 1 '11 at 10:03
  • @Martin: On second thoughts, I thought of a use for CW mode so, yes please hit it with Mjolnir. – Loop Space Apr 1 '11 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. – Martin Scharrer Apr 1 '11 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! – Loop Space Apr 1 '11 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 Apr 1 '11 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. – barbara beeton Sep 14 '11 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! – Loop Space Sep 14 '11 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. – barbara beeton Sep 16 '11 at 15:15

39 Answers 39

up vote 6 down vote accepted

Volunteers

  • I would volunteer, but I don't think I'd be any use. I can offer to test the package, though... – Seamus Apr 6 '11 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 Apr 7 '11 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 Apr 7 '11 at 18:29

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).

  • 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 May 31 '11 at 2:58

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

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

  • 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 Apr 6 '11 at 12:30
  • I am referring to this one – Seamus Apr 6 '11 at 12:31
  • @Seamus That's not a bad idea. Shall I do that? Others' comments? – Alan Munn Apr 7 '11 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 Apr 7 '11 at 7:59

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

TikZ/PGF Answer:

Drawing Mechanical Systems in LaTeX

Brief Description:

Easily drawing draw masses, springs, dampers and grounds.

enter image description here

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.

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

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.

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

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

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

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

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.

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

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.

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
  • Just to note that the latest version of the braids "package" already implements many of these improvements. – Loop Space May 26 '11 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? – Charles Stewart May 26 '11 at 12:54
  • Edited as requested. I'll have to make a "PGF Guru" sign for my office door. – Loop Space May 26 '11 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! – Loop Space Jun 3 '11 at 19:16

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.

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
  • This is similar to what Joseph Wright's chemscheme does, isn't it? – Seamus Apr 1 '11 at 11: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...

  • tcolorbox is surely a good fit for this – Carel Jan 1 '17 at 8:46

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.

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

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

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

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
  • 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 Apr 12 '11 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 Apr 12 '11 at 18:51
  • 1
    This is now in pgflibraryshapes.tex-sx (without mid and base) – Caramdir Jun 23 '11 at 20:17

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.

  • 6
    I don't think this is the sort of thing that needs doing often enough that it needs putting in a package. – Seamus Apr 15 '11 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 Apr 19 '11 at 4:00

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

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.

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)
  • Adding shiny glass-like effect may be interesting, see the example tex.stackexchange.com/q/47273/9467 – kiss my armpit Mar 9 '12 at 15:13
  • For the interested, it is still under construction to make it an explicit .sty file with additional goodies. – percusse Mar 19 '12 at 11:38

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 .