Skip to content

Latex tikz Drawing Package

Drawing Shapes Inline in LaTeX with TikZ

In LaTeX, you can draw shapes inline with text using the TikZ package, which allows for seamless integration of graphics between characters. Here’s how to accomplish this:

Basic Setup

First, include the necessary packages in your preamble:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,positioning}

Method 1: Using \tikz Inline Command

The \tikz command allows you to draw shapes directly within text:

This is a sentence with a \tikz \fill[red] (0,0) circle (0.2em); red circle in it.

Here's a \tikz[baseline=(char.base)]{\node[draw,circle,inner sep=2pt] (char) {A};}
boxed letter in text.

Method 2: Creating Reusable Commands

For convenience, define commands for frequently used shapes:

\newcommand{\inlinecircle}[1]{%
  \tikz[baseline=(char.base)]{%
    \node[circle,fill=#1,inner sep=1.5pt] (char) {};}%
}

\newcommand{\inlinesquare}[1]{%
  \tikz[baseline=(char.base)]{%
    \node[rectangle,fill=#1,inner sep=1.5pt] (char) {};}%
}

Then use them in your text:

This text has a blue \inlinecircle{blue} circle and a red \inlinesquare{red} square.

Method 3: Smoke-like Effects

For smoke-like effects, you can use TikZ’s path decorations:

\usetikzlibrary{decorations.pathmorphing}

\newcommand{\smokeshape}[1]{%
  \tikz[baseline=(char.base)]{%
    \node[inner sep=0pt] (char) {};
    \draw[#1, decoration={random steps, segment length=3pt, amplitude=1pt}, 
          decorate] (0,0) circle (0.3em);
  }%
}

Use it like this:

The text has a smoky \smokeshape{draw=gray, fill=black!20} effect between words.

Complete Example

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,decorations.pathmorphing}

\newcommand{\smokecircle}[2][]{%
  \tikz[baseline=(char.base)]{%
    \node[inner sep=0pt] (char) {};
    \draw[#1, decoration={random steps, segment length=2pt, amplitude=0.8pt}, 
          decorate, fill=#2, opacity=0.8] (0,0) circle (0.25em);
  }%
}

\begin{document}
This is normal text with a \smokecircle[draw=gray]{black!30} smoke puff inserted
between the words. You can have multiple \smokecircle{gray!40} \smokecircle{gray!60} 
\smokecircle{black!20} smoke effects of different colors.
\end{document}

The baseline alignment is crucial to ensure your shapes align properly with the text. Adjust the sizes using em units to scale with the font size.

#latax #tikz #bookwriting

Leave a Reply

Your email address will not be published. Required fields are marked *