# Basti’s Buggy Blog

Poking at software.

# Quick and Beautiful Figures in LaTeX without TikZ

TikZ figures in LaTeX documents offer precise control over graphic output, while allowing for a consistent look-and-feel. But especially for figures which require a lot of manual positioning, programmatically creating TikZ figures can be a tedious task. If you do not require publishing-quality graphics (although I have seen worse pictures there), this workflow might be suitable for you.

## Create Your Sketch in draw.io

1. Open the draw.io offline or online app
2. Make sure to select the correct paper size (A4/Letter) of your LaTeX document to get a feel for the resulting size of your figure
3. Draw (.io)!

Note: If you want to use the Font used by draw.io, you can stop right here and export your images as a pdf (File > Export > PDF).

## Prepare the SVG Export

Before exporting the draw.io figure into the SVG format, make sure to untick the “Word Wrap” and “Formatted Text” checkbox in every element containing text.

In the next step we will prepend LaTeX commands to every text element, which gives us the possibility to adjust the font size and type later. We do this by using one-letter commands, which we will declare later. Just make sure to use different command names for text elements which shall be styled differently. For example, I will use use \h for headings, \f for filenames, \l for the legend text and \d for the vertical dividers. The result looks like this:

Don’t worry about messing up any text alignment with the prepended LaTeX commands, they will disappear later.

## Exporting the SVG

1. Select all elements in draw.io (Ctrl+A)
2. File > Export as > SVG…

Select the following options and press the export button:

## Open the SVG in Inkscape

In our last conversion step we need to open (not import) the exported SVG in Inkscape.

1. File > Save a Copy… > Select “.pdf”
2. In the next dialog box, select the “Omit text in PDF and create LaTeX file” radio item

This will generate two files:

• figure.pdf: Contains the figure without text
• figure.pdf_tex: LaTeX file which imports the PDF and adds the text

## Embed the Figure in LaTeX

In our final step we will include the figure in our LaTeX document and change the text appearance. Instead of \includegraphic[...]{...}, we use \input{figure.pdf_tex} to include our figure.

In order to control the width, we redefine the \svgwidth variable with the desired absolute width. To change appearance of our text, we define the commands we used earlier by using \def\cmd{...}. Make sure to wrap the \def and \input commands in parentheses {} in order to prevent overriding commands for the whole document.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}\pgfplotsset{compat=1.17}
\usepackage[left=2cm,right=2cm]{geometry}

\begin{document}
\begin{figure}
\centering
{
\def\svgwidth{0.8\linewidth}
\def\h{\bf}
\def\d{}
\def\f{\small\tt}
\def\l{\footnotesize}
\input{figure.pdf_tex}
}
\end{figure}
\end{document}

The result looks like this: