Master TikZ Figures with ChatGPT for High-Impact Academic Writing in LaTeX

Woman student working on Latex paper.
Student working on figures for her academic paper.

I am at the CHI 2023 conference this week and receiving so much information (as usual) about everything related to human-computer interaction. I also enjoyed teaching my CHI writing course to a small cohort at this conference again. If you're interested in going through the course slides, you can find them here. One of the things, I taught students in the course is how to quickly create a TikZ figure with the help of ChatGPT when you are writing a paper in LaTeX (this is a markup language that is popular for scientific publications). I want to quickly break down this process for you today. Below you can see the figure we'll be creating.

The TikZ diagram we'll create here with the help of ChatGPT

In academic writing, we frequently create process diagrams, such as experimental flow diagrams, to explain complex processes. We can easily design these using the free TikZ package on the online LaTeX platform Overleaf. The TikZ package is a versatile tool for creating high-quality, customizable graphics, ideal for scientific, mathematical, and engineering diagrams. It supports a variety of features, from simple line drawings to complex 3D visualizations. Overleaf, an online LaTeX editor, enables users to collaborate on documents via a user-friendly interface, offering many templates and examples for seamless project creation and sharing. However, the process of creating a TikZ figure in Overleaf can be time-consuming, especially for someone not proficient in LaTeX, like myself. To efficiently create a figure in this code, I sought assistance from ChatGPT. Here's how I proceeded:

  1. Think about the type of diagram and how to describe it in natural language. I then prompted ChatGPT-4 the following: "Act as a LaTeX code expert. I want to create a horizontal flow diagram using TikZ to show the experimental setup flow with blocks. Generate TikZ code for a box flow diagram that shows this flow: RQ -> Literature Review -> Var 1 Test -> Exposure to Var 1 Test -> Post-test Questionnaires -> User Interviews -> Debrief." You can see that I told ChatGPT explicitly what I wanted to do and gave a brief breakdown of the process flow without making it too complex yet. It's important to mention that it should be horizontal, so it does not just move around the blocks in circles. It continued to generate usable LaTeX code TikZ code, starting with the inclusion of the package for the document: \usepackage{tikz} \usetikzlibrary{shapes,arrows,positioning}
  2. Then, I decided I wanted to add colour (specifically the CHI 2023 colours) and make everything look more uniform. The prompt continued as: "Make all the boxes the same height to look more uniform. Then, I want to colour the background of the boxes in a complementary colour scheme inspired by these colours: #107AC1, #FBC63D, #C53E31. Ensure good contrast ratios between text and background colours. Make the connecting arrows thicker. Break down the text inside the boxes into two lines. Make the font inside the text boxes larger. Be sure to use xcolor to create colour definitions first."
  3. It continued to produce an interesting diagram. I had to make sure \usepackage{xcolor} was included in the header. I then asked it to rename colours ("Change the colour names from color1, etc. to names that represent the colours. Make the colour semitransparent at an alpha level of 70%"). Now, all that was left to do was add the splitting of variables in the experimental design and add a second row of boxes for this. I did this, but I explicitly said what I needed the diagram to look like.
  4. Here is the final prompt: "I want to add a box under Var 1 Test called Var 2 Test and split the input arrow from Literature Review to go towards that as well. Connect this to a box called Exposure to Var 2 test right under Var 1 test, connect this box back to the same Post-test questionnaires box." This continued to produce the image you see above.

This little experiment showed me how quickly I can create awesome-looking TikZ figures with half of the code tinkering that I usually do to get them to look right. Hope this little tip is helpful to you. I will continue to enjoy the CHI conference, and if you're on Twitter, feel free to follow my journey there.